Commit Graph

6800 Commits

Author SHA1 Message Date
Reid Kleckner 290feb9c19 [MS] Fix function type mangling of default ctor closures
Use the canonical decl in pointer comparisons with the default
constructor closure decl. Otherwise we don't produce the correct
"@@QAEXXZ" mangling, which essentially means "void(void) thiscall public
instance method".

llvm-svn: 291448
2017-01-09 17:04:37 +00:00
George Burgess IV 177399e227 Add the diagnose_if attribute to clang.
`diagnose_if` can be used to have clang emit either warnings or errors
for function calls that meet user-specified conditions. For example:

```
constexpr int foo(int a)
  __attribute__((diagnose_if(a > 10, "configurations with a > 10 are "
                                      "expensive.", "warning")));

int f1 = foo(9);
int f2 = foo(10); // warning: configuration with a > 10 are expensive.
int f3 = foo(f2);
```

It currently only emits diagnostics in cases where the condition is
guaranteed to always be true. So, the following code will emit no
warnings:

```
constexpr int bar(int a) {
  foo(a);
  return 0;
}

constexpr int i = bar(10);
```

We hope to support optionally emitting diagnostics for cases like that
(and emitting runtime checks) in the future.

Release notes will appear shortly. :)

Differential Revision: https://reviews.llvm.org/D27424

llvm-svn: 291418
2017-01-09 04:12:14 +00:00
Faisal Vali c72a08c1f6 [cxx1z-constexpr-lambda] Implement constant evaluation of non-capturing lambda expressions.
Add a visitor for lambda expressions to RecordExprEvaluator in ExprConstant.cpp that creates an empty APValue of Struct type to represent the closure object. Additionally, add a LambdaExpr visitor to the TemporaryExprEvaluator that forwards constant evaluation of immediately-called-lambda-expressions to the one in RecordExprEvaluator through VisitConstructExpr.

This patch supports:
constexpr auto ID = [] (auto a) { return a; };
static_assert(ID(3.14) == 3.14);
static_assert([](auto a) { return a + 1; }(10) == 11);

Lambda captures are still not supported for constexpr lambdas.

llvm-svn: 291416
2017-01-09 03:02:53 +00:00
Faisal Vali d92e7499fb [cxx1z-constexpr-lambda] Make conversion function constexpr, and teach the expression-evaluator to evaluate the static-invoker.
This patch has been sitting in review hell since july 2016 and our lack of constexpr lambda support is getting embarrassing (given that I've had a branch that implements the feature (modulo *this capture) for over a year.  While in Issaquah I was enjoying shamelessly trying to convince folks of the lie that this was Richard's fault ;) I won't be able to do so in Kona since I won't be attending - so I'm going to aim to have this feature be implemented by then.

I'm quite confident of the approach in this patch, which simply maps the static-invoker 'thunk' back to the corresponding call-operator (specialization).

Thanks!

llvm-svn: 291397
2017-01-08 18:56:11 +00:00
Akira Hatanaka d62f2c8c0a Make ASTContext::getDeclAlign return the correct alignment for
FunctionDecls.

This commit silences an incorrect warning that is issued when a function
pointer is cast to another function pointer type. The warning gets
issued because alignments of the source and destination do not match in
Sema::CheckCastAlign, which happens because ASTContext::getTypeInfoImpl
and ASTContext::getDeclAlign return different values for functions (the
former returns 4 while the latter returns 1).

This should fix PR31558.

rdar://problem/29533528

Differential Revision: https://reviews.llvm.org/D27478

llvm-svn: 291253
2017-01-06 17:56:15 +00:00
George Burgess IV 7fb7e361bf Re-add objectsize function/incomplete type checks.
I accidentally omitted these when refactoring this code. This caused
problems when building parts of the test-suite on MacOS.

llvm-svn: 290916
2017-01-03 23:35:19 +00:00
Kelvin Li 1851df563d [OpenMP] Sema and parsing for 'target teams distribute parallel for simd’ pragma
This patch is to implement sema and parsing for 'target teams distribute parallel for simd’ pragma.

Differential Revision: https://reviews.llvm.org/D28202

llvm-svn: 290862
2017-01-03 05:23:48 +00:00
Kelvin Li 80e8f56284 [OpenMP] Sema and parsing for 'target teams distribute parallel for’ pragma
This patch is to implement sema and parsing for 'target teams distribute parallel for’ pragma.

Differential Revision: https://reviews.llvm.org/D28160

llvm-svn: 290725
2016-12-29 22:16:30 +00:00
George Burgess IV b531698ff0 Emit CCEDiags when evaluating a const variable.
This addresses post-review feedback from r290577.

llvm-svn: 290584
2016-12-27 05:33:20 +00:00
David Majnemer a5cfddc367 [MS ABI] Mangle unnamed enums correctly
Unnamed enums take the name of the first enumerator they define.

llvm-svn: 290509
2016-12-25 05:26:02 +00:00
Kelvin Li 83c451e998 [OpenMP] Sema and parsing for 'target teams distribute' pragma
This patch is to implement sema and parsing for 'target teams distribute' pragma.

Differential Revision: https://reviews.llvm.org/D28015

llvm-svn: 290508
2016-12-25 04:52:54 +00:00
Richard Smith 792c22dbd4 When producing a name of a partial specialization in a diagnostic, use the
template arguments as written rather than the canonical template arguments,
so we print more user-friendly names for template parameters.

llvm-svn: 290483
2016-12-24 04:09:05 +00:00
Egor Churaev 28f00aab73 [OpenCL] Align fake address space map with the SPIR target maps.
Summary:
We compile user opencl kernel code with spir triple. But built-ins are written in OpenCL and we compile it with triple x86_64 to be able to use x86 intrinsics. And we need address spaces to match in both cases. So, we change fake address space map in OpenCL for matching with spir.

On CPU address spaces are not really important but we'd like to preserve address space information in order to perform optimizations relying on this info like enhanced alias analysis.

Reviewers: pekka.jaaskelainen, Anastasia

Subscribers: pekka.jaaskelainen, yaxunl, bader, cfe-commits

Differential Revision: https://reviews.llvm.org/D28048

llvm-svn: 290436
2016-12-23 16:11:25 +00:00
Egor Churaev 89831421af Fix problems in "[OpenCL] Enabling the usage of CLK_NULL_QUEUE as compare operand."
Summary: Fixed warnings in commit: https://reviews.llvm.org/rL290171

Reviewers: djasper, Anastasia

Subscribers: yaxunl, cfe-commits, bader

Differential Revision: https://reviews.llvm.org/D27981

llvm-svn: 290431
2016-12-23 14:55:49 +00:00
Richard Smith 43e14d271c Move generation of injected template arguments for a template parameter list
out of an internal function and into ASTContext; this is needed in template
argument deduction for P0522R0.

llvm-svn: 290405
2016-12-23 02:10:11 +00:00
Richard Smith 593d6a168f When merging two deduced non-type template arguments for the same parameter,
fail the merge if the arguments have different types (except if one of them was
deduced from an array bound, in which case take the type from the other).

This is correct because (except in the array bound case) the type of the
template argument in each deduction must match the type of the parameter, so at
least one of the two deduced arguments must have a mismatched type.

This is necessary because we would otherwise lose the type information for the
discarded template argument in the merge, and fail to diagnose the mismatch.

In order to power this, we now properly retain the type of a deduced non-type
template argument deduced from a declaration, rather than giving it the type of
the template parameter; we'll convert it to the template parameter type when
checking the deduced arguments.

llvm-svn: 290399
2016-12-23 01:30:39 +00:00
George Burgess IV e37633713d Add the alloc_size attribute to clang, attempt 2.
This is a recommit of r290149, which was reverted in r290169 due to msan
failures. msan was failing because we were calling
`isMostDerivedAnUnsizedArray` on an invalid designator, which caused us
to read uninitialized memory. To fix this, the logic of the caller of
said function was simplified, and we now have a `!Invalid` assert in
`isMostDerivedAnUnsizedArray`, so we can catch this particular bug more
easily in the future.

Fingers crossed that this patch sticks this time. :)

Original commit message:

This patch does three things:
- Gives us the alloc_size attribute in clang, which lets us infer the
  number of bytes handed back to us by malloc/realloc/calloc/any user
  functions that act in a similar manner.
- Teaches our constexpr evaluator that evaluating some `const` variables
  is OK sometimes. This is why we have a change in
  test/SemaCXX/constant-expression-cxx11.cpp and other seemingly
  unrelated tests. Richard Smith okay'ed this idea some time ago in
  person.
- Uniques some Blocks in CodeGen, which was reviewed separately at
  D26410. Lack of uniquing only really shows up as a problem when
  combined with our new eagerness in the face of const.

llvm-svn: 290297
2016-12-22 02:50:20 +00:00
Richard Smith 505ef81422 Fix defaulted-functions-in-C++98 extension to give the functions the same
effect they would have in C++11. In particular, they do not prevent
value-initialization from performing zero-initialization, nor do they prevent a
struct from being an aggregate.

llvm-svn: 290229
2016-12-21 01:57:02 +00:00
Richard Smith 151c456858 [c++1z] P0195R2: Support pack-expansion of using-declarations.
This change introduces UsingPackDecl as a marker for the set of UsingDecls
produced by pack expansion of a single (unresolved) using declaration. This is
not strictly necessary (we just need to be able to map from the original using
declaration to its expansions somehow), but it's useful to maintain the
invariant that each declaration reference instantiates to refer to one
declaration.

This is a re-commit of r290080 (reverted in r290092) with a fix for a
use-after-lifetime bug.

llvm-svn: 290203
2016-12-20 21:35:28 +00:00
Alexey Bataev a7206b9e09 [OPENMP] Fix for PR31416: Clang crashes on OMPCapturedExpr during source
based coverage compilation

Added source location info to captured expression declaration + fixed
source location info for loop based directives.

llvm-svn: 290181
2016-12-20 16:51:02 +00:00
Daniel Jasper 9068938eb0 Revert "[OpenCL] Enabling the usage of CLK_NULL_QUEUE as compare operand."
This reverts commit r290171. It triggers a bunch of warnings, because
the new enumerator isn't handled in all switches. We want a warning-free
build.

Replied on the commit with more details.

llvm-svn: 290173
2016-12-20 10:05:04 +00:00
Egor Churaev 67c3f3ec68 [OpenCL] Enabling the usage of CLK_NULL_QUEUE as compare operand.
Summary: Enabling the compression of CLK_NULL_QUEUE to variable of type queue_t.

Reviewers: Anastasia

Subscribers: cfe-commits, yaxunl, bader

Differential Revision: https://reviews.llvm.org/D27569

llvm-svn: 290171
2016-12-20 09:15:21 +00:00
Chandler Carruth d7738fe6ad Revert r290149: Add the alloc_size attribute to clang.
This commit fails MSan when running test/CodeGen/object-size.c in
a confusing way. After some discussion with George, it isn't really
clear what is going on here. We can make the MSan failure go away by
testing for the invalid bit, but *why* things are invalid isn't clear.
And yet, other code in the surrounding area is doing precisely this and
testing for invalid.

George is going to take a closer look at this to better understand the
nature of the failure and recommit it, for now backing it out to clean
up MSan builds.

llvm-svn: 290169
2016-12-20 08:28:19 +00:00
George Burgess IV a747027bc6 Add the alloc_size attribute to clang.
This patch does three things:

- Gives us the alloc_size attribute in clang, which lets us infer the
  number of bytes handed back to us by malloc/realloc/calloc/any user
  functions that act in a similar manner.
- Teaches our constexpr evaluator that evaluating some `const` variables
  is OK sometimes. This is why we have a change in
  test/SemaCXX/constant-expression-cxx11.cpp and other seemingly
  unrelated tests. Richard Smith okay'ed this idea some time ago in
  person.
- Uniques some Blocks in CodeGen, which was reviewed separately at
  D26410. Lack of uniquing only really shows up as a problem when
  combined with our new eagerness in the face of const.

Differential Revision: https://reviews.llvm.org/D14274

llvm-svn: 290149
2016-12-20 01:05:42 +00:00
Richard Smith 836de6babb Fix completely bogus types for some builtins:
* In C++, never create a FunctionNoProtoType for a builtin (fixes C++1z
   crasher from r289754).

 * Fix type of __sync_synchronize to be a no-parameter function rather than a
   varargs function. This matches GCC.

 * Fix type of vfprintf to match its actual type. We gave it a wrong type due
   to PR4290 (apparently autoconf generates invalid code and expects compilers
   to choke it down or it miscompiles the program; the relevant error in clang
   was downgraded to a warning in r122744 to fix other occurrences of this
   autoconf brokenness, so we don't need this workaround any more).

 * Turn off vararg argument checking for __noop, since it's not *really* a
   varargs function. Alternatively we could add custom type checking for it
   and synthesize parameter types matching the actual arguments in each call,
   but that seemed like overkill.

llvm-svn: 290146
2016-12-19 23:59:34 +00:00
Daniel Jasper 9949ead55a Revert "[c++1z] P0195R2: Support pack-expansion of using-declarations."
This reverts commit r290080 as it leads to many Clang crashes, e.g.:
http://lab.llvm.org:8011/builders/clang-cmake-aarch64-quick/builds/1814

llvm-svn: 290092
2016-12-19 10:09:25 +00:00
Richard Smith 22a250cd5d [c++1z] P0195R2: Support pack-expansion of using-declarations.
This change introduces UsingPackDecl as a marker for the set of UsingDecls
produced by pack expansion of a single (unresolved) using declaration. This is
not strictly necessary (we just need to be able to map from the original using
declaration to its expansions somehow), but it's useful to maintain the
invariant that each declaration reference instantiates to refer to one
declaration.

llvm-svn: 290080
2016-12-19 04:08:53 +00:00
Richard Smith d8a9e37558 Fix some interactions between C++11 and C++14 features and using-declarations:
* a dependent non-type using-declaration within a function template can be
   valid, as it can refer to an enumerator, so don't reject it in the template
   definition
 * we can partially substitute into a dependent using-declaration if it appears
   within a (local class in a) generic lambda within a function template, which
   means an UnresolvedUsing*Decl doesn't necessarily instantiate to a UsingDecl.

llvm-svn: 290071
2016-12-18 21:39:37 +00:00
Kelvin Li bf594a5600 [OpenMP] Sema and parsing for 'target teams' pragma
This patch is to implement sema and parsing for 'target teams' pragma.

Differential Revision: https://reviews.llvm.org/D27818

llvm-svn: 290038
2016-12-17 05:48:59 +00:00
Yaxun Liu 402804b6d6 Re-commit r289252 and r289285, and fix PR31374
llvm-svn: 289787
2016-12-15 08:09:08 +00:00
Richard Smith dfe85e2d88 [c++1z] Permit constant evaluation of a call through a function pointer whose
type differs from the type of the actual function due to having a different
exception specification.

llvm-svn: 289754
2016-12-15 02:35:39 +00:00
Nico Weber 7849eeb035 Revert 289252 (and follow-up 289285), it caused PR31374
llvm-svn: 289713
2016-12-14 21:38:18 +00:00
Stephan Bergmann 17c7f70362 Replace APFloatBase static fltSemantics data members with getter functions
At least the plugin used by the LibreOffice build
(<https://wiki.documentfoundation.org/Development/Clang_plugins>) indirectly
uses those members (through inline functions in LLVM/Clang include files in turn
using them), but they are not exported by utils/extract_symbols.py on Windows,
and accessing data across DLL/EXE boundaries on Windows is generally
problematic.

Differential Revision: https://reviews.llvm.org/D26671

llvm-svn: 289647
2016-12-14 11:57:17 +00:00
Richard Smith 30e304e2a6 Remove custom handling of array copies in lambda by-value array capture and
copy constructors of classes with array members, instead using
ArrayInitLoopExpr to represent the initialization loop.

This exposed a bug in the static analyzer where it was unable to differentiate
between zero-initialized and unknown array values, which has also been fixed
here.

llvm-svn: 289618
2016-12-14 00:03:17 +00:00
Peter Collingbourne 2849c4e841 CodeGen: New vtable group representation: struct of vtable arrays.
In a future change, this representation will allow us to use the new inrange
annotation on getelementptr to allow the optimizer to split vtable groups.

Differential Revision: https://reviews.llvm.org/D22296

llvm-svn: 289584
2016-12-13 20:40:39 +00:00
Reid Kleckner 06df402b06 Align EvalInfo in ExprConstant to avoid PointerUnion assertions
32-bit MSVC doesn't provide more than 4 byte stack alignment by default.
This conflicts with PointerUnion's attempt to make assertions about
alignment. This fixes the problem by explicitly asking the compiler for
8 byte alignment.

llvm-svn: 289575
2016-12-13 19:48:32 +00:00
Richard Smith 410306bf6e Add two new AST nodes to represent initialization of an array in terms of
initialization of each array element:

 * ArrayInitLoopExpr is a prvalue of array type with two subexpressions:
   a common expression (an OpaqueValueExpr) that represents the up-front
   computation of the source of the initialization, and a subexpression
   representing a per-element initializer
 * ArrayInitIndexExpr is a prvalue of type size_t representing the current
   position in the loop

This will be used to replace the creation of explicit index variables in lambda
capture of arrays and copy/move construction of classes with array elements,
and also C++17 structured bindings of arrays by value (which inexplicably allow
copying an array by value, unlike all of C++'s other array declarations).

No uses of these nodes are introduced by this change, however.

llvm-svn: 289413
2016-12-12 02:53:20 +00:00
Yaxun Liu 8f66b4b44a Add support for non-zero null pointer for C and OpenCL
In amdgcn target, null pointers in global, constant, and generic address space take value 0 but null pointers in private and local address space take value -1. Currently LLVM assumes all null pointers take value 0, which results in incorrectly translated IR. To workaround this issue, instead of emit null pointers in local and private address space, a null pointer in generic address space is emitted and casted to local and private address space.

Tentative definition of global variables with non-zero initializer will have weak linkage instead of common linkage since common linkage requires zero initializer and does not have explicit section to hold the non-zero value.

Virtual member functions getNullPointer and performAddrSpaceCast are added to TargetCodeGenInfo which by default returns ConstantPointerNull and emitting addrspacecast instruction. A virtual member function getNullPointerValue is added to TargetInfo which by default returns 0. Each target can override these virtual functions to get target specific null pointer and the null pointer value for specific address space, and perform specific translations for addrspacecast.

Wrapper functions getNullPointer is added to CodegenModule and getTargetNullPointerValue is added to ASTContext to facilitate getting the target specific null pointers and their values.

This change has no effect on other targets except amdgcn target. Other targets can provide support of non-zero null pointer in a similar way.

This change only provides support for non-zero null pointer for C and OpenCL. Supporting for other languages will be added later incrementally.

Differential Revision: https://reviews.llvm.org/D26196

llvm-svn: 289252
2016-12-09 19:01:11 +00:00
Richard Smith b8c0f553ed DR1295 and cleanup for P0135R1: Make our initialization code more directly
mirror the description in the standard. Per DR1295, this means that binding a
const / rvalue reference to a bit-field no longer "binds directly", and per
P0135R1, this means that we materialize a temporary in reference binding
after adjusting cv-qualifiers and before performing a derived-to-base cast.

In C++11 onwards, this should have fixed the last case where we would
materialize a temporary of the wrong type (with a subobject adjustment inside
the MaterializeTemporaryExpr instead of outside), but we still have to deal
with that possibility in C++98, unless we want to start using xvalues to
represent materialized temporaries there too.

llvm-svn: 289250
2016-12-09 18:49:13 +00:00
Reid Kleckner 078aea9043 Store decls in prototypes on the declarator instead of in the AST
This saves two pointers from FunctionDecl that were being used for some
rare and questionable C-only functionality.  The DeclsInPrototypeScope
ArrayRef was added in r151712 in order to parse this kind of C code:

    enum e {x, y};
    int f(enum {y, x} n) {
     return x; // should return 1, not 0
    }

The challenge is that we parse 'int f(enum {y, x} n)' it its own
function prototype scope that gets popped before we build the
FunctionDecl for 'f'. The original change was doing two questionable
things:

1. Saving all tag decls introduced in prototype scope on a TU-global
Sema variable. This is problematic when you have cases like this, where
'x' and 'y' shouldn't be visible in 'f':
    void f(void (*fp)(enum { x, y } e)) { /* no x */ }
This patch fixes that, so now 'f' can't see 'x', which is consistent
with GCC.

2. Storing the decls in FunctionDecl in ActOnFunctionDeclarator so that
they could be used in ActOnStartOfFunctionDef. This is just an
inefficient way to move information around. The AST lives forever, but
the list of non-parameter decls in prototype scope is short lived.

Moving these things to the Declarator solves both of these issues.

Reviewers: rsmith

Subscribers: jmolloy, cfe-commits

Differential Revision: https://reviews.llvm.org/D27279

llvm-svn: 289225
2016-12-09 17:14:05 +00:00
Kelvin Li 7ade93f5e2 [OpenMP] Sema and parsing for 'teams distribute parallel for' pragma
This patch is to implement sema and parsing for 'teams distribute parallel for' pragma.
    
Differential Revision: https://reviews.llvm.org/D27345

llvm-svn: 289179
2016-12-09 03:24:30 +00:00
Richard Smith 122f88d481 [c++17] P0135R1: Guaranteed copy elision.
When an object of class type is initialized from a prvalue of the same type
(ignoring cv qualifications), use the prvalue to initialize the object directly
instead of inserting a redundant elidable call to a copy constructor.

llvm-svn: 288866
2016-12-06 23:52:28 +00:00
David Majnemer 984498ff9d [MS ABI] Implement more of the Itanium mangling rules
We didn't implement handle corner cases like:
 - lambdas used to initialize a field
 - lambdas in default argument initializers

This fixes PR31197.

Differential Revision: https://reviews.llvm.org/D27226

llvm-svn: 288826
2016-12-06 17:01:02 +00:00
Malcolm Parsons f92d44c673 Fix two clang-tidy misc-move-forwarding-reference warnings
Patch by Michael Sharpe.

llvm-svn: 288813
2016-12-06 14:49:18 +00:00
Richard Smith b3189a1802 DR1213: element access on an array xvalue or prvalue produces an xvalue. In the
latter case, a temporary array object is materialized, and can be
lifetime-extended by binding a reference to the member access. Likewise, in an
array-to-pointer decay, an rvalue array is materialized before being converted
into a pointer.

This caused IR generation to stop treating file-scope array compound literals
as having static storage duration in some cases in C++; that has been rectified
by modeling such a compound literal as an lvalue. This also improves clang's
compatibility with GCC for those cases.

llvm-svn: 288654
2016-12-05 07:49:14 +00:00
Eric Fiselier 283d8d45db [Sema] Don't perform aggregate initialization for types with explicit constructors
Summary:
The C++17 rules for aggregate initialization changed to disallow types with explicit constructors [dcl.init.aggr]p1. This patch implements that new rule.


Reviewers: rsmith

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D25654

llvm-svn: 288565
2016-12-03 01:26:47 +00:00
Jonathan Roelofs 28b9668db3 Delete tautological assertion.
After r256463, both the LHS and RHS now refer to the same variable. Before,
they referred to the member, the parameter respectively. Now GCC6's
-Wtautological-compare complains.

llvm-svn: 288444
2016-12-02 00:51:58 +00:00
Joey Gouly e3c85de6df [OpenCL] Refactor read_only/write_only pipes.
This adds the access qualifier to the Pipe Type, rather than using a class
hierarchy. 

It also fixes mergeTypes for Pipes, by disallowing merges. Only identical
pipe types can be merged. The test case in invalid-pipes-cl2.0.cl is added
to check that.

llvm-svn: 288332
2016-12-01 11:30:49 +00:00
Kelvin Li 579e41ced2 [OpenMP] Sema and parsing for 'teams distribute parallel for simd' pragma
This patch is to implement sema and parsing for 'teams distribute parallel for simd' pragma.

Differential Revision: https://reviews.llvm.org/D27084

llvm-svn: 288294
2016-11-30 23:51:03 +00:00
John McCall 843dfccdc5 getObjCEncodingForMethodDecl cannot fail. Simplify. NFC.
llvm-svn: 288203
2016-11-29 21:57:00 +00:00
Richard Smith 8110c9df22 Support constant expression evaluation for wchar_t versions of simple string
functions, in order to support constexpr std::char_traits<wchar_t>.

llvm-svn: 288193
2016-11-29 19:45:17 +00:00
Yaron Keren 633e14aa42 Correct comment: we are creating a canonicla decltypetype.
llvm-svn: 288124
2016-11-29 10:08:20 +00:00
Benjamin Kramer 60a53d5e16 [ASTDumper] Add some more character escapes for convenience.
llvm-svn: 287859
2016-11-24 09:41:33 +00:00
Reid Kleckner c01ee7505a Remove C++ default arg side table for MS ABI ctor closures
Summary:
We don't need a side table in ASTContext to hold CXXDefaultArgExprs. The
important part of building the CXXDefaultArgExprs was to ODR use the
default argument expressions, not to make AST nodes. Refactor the code
to only check the default argument, and remove the side table in
ASTContext which wasn't being serialized.

Fixes PR31121

Reviewers: thakis, rsmith, majnemer

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D27007

llvm-svn: 287774
2016-11-23 16:51:30 +00:00
Gabor Horvath 0866c2f5d4 [ASTImporter] Added ability to import AtomicType nodes
Patch by: Kareem Khazem

Differential Revision: https://reviews.llvm.org/D26328

llvm-svn: 287763
2016-11-23 15:24:23 +00:00
Richard Smith 5a2e6b97f7 Indicate in AST dump whether special member functions are defaulted and trivial.
llvm-svn: 287599
2016-11-21 23:43:54 +00:00
Alex Lorenz ff6c34b30d [ObjC] Prevent infinite loops when iterating over redeclaration
of a method that was declared in an invalid interface

This commit fixes an infinite loop that occurs when clang tries to iterate over
redeclaration of a method that was declared in an invalid @interface. The
existing validity checks don't catch this as that @interface is a duplicate of
a previously declared valid @interface declaration, so we have to verify that
the found redeclaration is in a valid declaration context.

rdar://29220965

Differential Revision: https://reviews.llvm.org/D26664

llvm-svn: 287530
2016-11-21 11:16:30 +00:00
Joey Gouly 5788b783ac [OpenCL] Introduce ReadPipeType and WritePipeType.
This allows Sema to diagnose passing a read_only pipe to a
write_only pipe argument.

llvm-svn: 287343
2016-11-18 14:10:54 +00:00
Manman Ren b666573238 ObjC Module: try to make objc module deterministic.
Make sure that comparing selectors in DeclarationName does its job.
rdar://problem/28988750

llvm-svn: 287244
2016-11-17 18:41:18 +00:00
Mehdi Amini dc9bf8fab6 Improve handling of __FUNCTION__ and other predefined expression for Objective-C Blocks
Instead of always displaying the mangled name, try to do better
and get something closer to regular functions.

Recommit r287039 (that was reverted in r287039) with a tweak to
be more generic, and test fixes!

Differential Revision: https://reviews.llvm.org/D26522

llvm-svn: 287085
2016-11-16 07:07:28 +00:00
Richard Smith 6328cbd31b Outline evaluation of calls to builtins to avoid inflating stack usage for the
common case of a call to a non-builtin, particularly for unoptimized ASan
builds (where the per-variable stack usage can be quite high).

llvm-svn: 287066
2016-11-16 00:57:23 +00:00
Mehdi Amini f5f37ee546 Revert "Improve handling of __FUNCTION__ and other predefined expression for Objective-C Blocks"
This reverts commit r287039, tests are broken.

llvm-svn: 287043
2016-11-15 22:19:50 +00:00
Mehdi Amini 26168ad5c5 Improve handling of __FUNCTION__ and other predefined expression for Objective-C Blocks
Instead of always displaying the mangled name, try to do better
and get something closer to regular functions.

Differential Revision: https://reviews.llvm.org/D26522

llvm-svn: 287039
2016-11-15 21:47:11 +00:00
Faisal Vali 0528a31ddf Fix PR28366: Handle variables from enclosing local scopes more gracefully during constant expression evaluation.
Only look for a variable's value in the constant expression evaluation activation frame, if the variable was indeed declared in that frame, otherwise it might be a constant expression and be usable within a nested local scope or emit an error.


void f(char c) { 
  struct X {
    static constexpr char f() { 
      return c; // error gracefully here as opposed to crashing.
    }
  };
  int I = X::f();
}

llvm-svn: 286748
2016-11-13 06:09:16 +00:00
Richard Smith e950795a03 [c++1z] Support constant folding for __builtin_strchr and __builtin_memchr.
llvm-svn: 286699
2016-11-12 01:39:56 +00:00
Richard Smith e151bab2fc [c++1z] Add constant-folding support for strcmp, strncmp, and memcmp, to
support constexpr char_traits.

llvm-svn: 286678
2016-11-11 23:43:35 +00:00
Richard Trieu cbd54304a3 When a DecompositionDecl is marked invalid, also set the child BindingDecl's to
invalid.

llvm-svn: 286630
2016-11-11 20:51:04 +00:00
Jordan Rose 303e2f1eac Accept nullability qualifiers on array parameters.
Since array parameters decay to pointers, '_Nullable' and friends
should be available for use there as well. This is especially
important for parameters that are typedefs of arrays. The unsugared
syntax for this follows the syntax for 'static'-sized arrays in C:

  void test(int values[_Nullable]);

This syntax was previously accepted but the '_Nullable' (and any other
attributes) were silently discarded. However, applying '_Nullable' to
a typedef was previously rejected and is now accepted; therefore, it
may be necessary to test for the presence of this feature:

  #if __has_feature(nullability_on_arrays)

One important change here is that DecayedTypes don't always
immediately contain PointerTypes anymore; they may contain an
AttributedType instead. This only affected one place in-tree, so I
would guess it's not likely to cause problems elsewhere.

This commit does not change -Wnullability-completeness just yet. I
want to think about whether it's worth doing something special to
avoid breaking existing clients that compile with -Werror. It also
doesn't change '#pragma clang assume_nonnull' behavior, which
currently treats the following two declarations as equivalent:

  #pragma clang assume_nonnull begin
  void test(void *pointers[]);
  #pragma clang assume_nonnull end

  void test(void * _Nonnull pointers[]);

This is not the desired behavior, but changing it would break
backwards-compatibility. Most likely the best answer is going to be
adding a new warning.

Part of rdar://problem/25846421

llvm-svn: 286519
2016-11-10 23:28:17 +00:00
Serge Pavlov a67a4d2f3c Make output of -ast-print a valid C++ code.
Output generated by option -ast-print looks like C/C++ code, and it
really is for plain C. For C++ the produced output was not valid C++
code, but the differences were small. With this change the output
is fixed and can be compiled. Tests are changed so that output produced
by -ast-print is compiled again with the same flags and both outputs are
compared.

Option -ast-print is extensively used in clang tests but it itself
was tested poorly, existing tests only checked that compiler did not
crash. There are unit tests in file DeclPrinterTest.cpp, but they test
only terse output mode.

Differential Revision: https://reviews.llvm.org/D26452

llvm-svn: 286439
2016-11-10 08:49:37 +00:00
Alex Lorenz ddbe0f5138 [AST] Dump dependent scope member expression with its member name
llvm-svn: 286365
2016-11-09 14:02:18 +00:00
Sean Callanan 24c5fe6b34 When the ASTImporter imports a source location, it avoids importing macro
expansions by calling getSpellingLoc(). That's great in most cases, but for
macros defined in the '<built-in>' source file, the source file is invalid
and does not import correctly, causing an assertion failure (the assertion
is Invalid SLocOffset or bad function choice).

A more reliable way to avoid this is to use getFileLoc(), which does not
return built-in locations. This avoids the crash but still preserves valid
source locations.

I've added a testcase that covers the previously crashing scenario.

https://reviews.llvm.org/D26054

llvm-svn: 286144
2016-11-07 20:42:25 +00:00
Chandler Carruth 59666777fb Add some more asserts to clearly indicate that there are special cases
which guarantee pointers are not null. These all seem to have useful
properties and correlations to document, in one case we even had it in
a comment but now it will also be an assert.

This should prevent PVS-Studio from incorrectly claiming that there are
a bunch of potential bugs here. But I feel really strongly that the
PVS-Studio warnings that pointed at this code have a far too high
false-positive rate to be entirely useful. These are just places where
there did seem to be a useful invariant to document and verify with an
assert. Several other places in the code were already correct and
already have perfectly clear code documenting and validating their
invariants, but still ran afoul of PVS-Studio.

llvm-svn: 285985
2016-11-04 06:32:57 +00:00
Serge Pavlov 08c8de215c Do not print enum underlying type if language is not C++11
Output generated by option '-ast-print' must not contains enum
base type specifications if source language does not include C++11.

llvm-svn: 285979
2016-11-04 06:03:34 +00:00
Richard Smith 018ac39f94 Improve obvious-most-derived-type devirtualization:
* if the base is produced by a series of derived-to-base conversions, check
    the expression inside them when looking for an expression with a known
    dynamic type
  * step past MaterializeTemporaryExprs when checking for a known dynamic type
  * when checking for a known dynamic type, treat all class prvalues as having
    a known dynamic type after skipping all relevant rvalue subobject
    adjustments
  * treat callees formed by pointer-to-member access for a non-reference member
    type like callees formed by member access.

llvm-svn: 285954
2016-11-03 18:55:18 +00:00
Richard Smith ef09aa9023 Update manglings for C++17 noexcept function types to match Jason Merrill's
proposal on cxx-abi-dev earlier today.

llvm-svn: 285870
2016-11-03 00:27:54 +00:00
Richard Smith 14d0484a16 Teach clang-query to dump types. I couldn't find any existing tests for clang-query's dumping functionality. =(
llvm-svn: 285869
2016-11-02 23:57:18 +00:00
Erich Keane 757d317c24 regcall: Implement regcall Calling Conv in clang
This patch implements the register call calling convention, which ensures
as many values as possible are passed in registers. CodeGen changes
were committed in https://reviews.llvm.org/rL284108.

Differential Revision: https://reviews.llvm.org/D25204

llvm-svn: 285849
2016-11-02 18:29:35 +00:00
Alex Lorenz 560ae565e9 Add a note that points to the linkage specifier for the C++ linkage errors
This commit improves the "must have C++ linkage" error diagnostics that are
emitted for C++ declarations like templates and literal operators by adding an
additional note that points to the appropriate extern "C" linkage specifier.

rdar://19021120

Differential Revision: https://reviews.llvm.org/D26189

llvm-svn: 285823
2016-11-02 15:46:34 +00:00
Manuel Klimek da7456ad0e Fix parenthesized assert (nfc).
llvm-svn: 285685
2016-11-01 10:30:50 +00:00
Michael Zuckerman 2460bada56 [x86][inline-asm] Add support for curly brackets escape using "%" in extended inline asm.
Commit on behalf of mharoush

After LGTM and check all:

This patch is a compatibility fix for clang, matching GCC support for charter escape when using extended in-line assembly (i.e, "%{" ,"%}" --> "{" ,"}" ).
 It is meant to enable support for advanced features such as AVX512 conditional\masked vector instructions/broadcast assembly syntax.

Reviewer: 1. rnk

Differential Revision: https://reviews.llvm.org/D25012

llvm-svn: 285585
2016-10-31 15:27:54 +00:00
Serge Pavlov dc586c4ee4 Make output of ast-print closer to C++ code
Put semicolon after non-defining method declaration and a class
specialization body.

llvm-svn: 285543
2016-10-31 05:11:12 +00:00
Richard Smith e0ab873a84 PR30831: Teach template type diffing to cope with TemplateSpecializationTypes
that desugar to non-TSTs (such as injected-class-names).

llvm-svn: 285437
2016-10-28 19:54:43 +00:00
Richard Smith 9b18217992 Fix implementation of the likely resolution of core issue 253 to support class
based arrays. Patch by Ian Tessier!

Differential Review: https://reviews.llvm.org/D25974

llvm-svn: 285430
2016-10-28 19:11:18 +00:00
Justin Lebar 0241c961e1 Relax assertion in FunctionDecl::doesDeclarationForceExternallyVisibleDefinition.
Previously we were asserting that this declaration doesn't have a body
*and* won't have a body after we continue parsing.  This is too strong
and breaks the go-bindings test during codegen.

llvm-svn: 285412
2016-10-28 16:46:39 +00:00
Justin Lebar 2b42ccc78b [CUDA] [AST] Allow isInlineDefinitionExternallyVisible to be called on functions without bodies.
Summary:
In CUDA compilation, we call isInlineDefinitionExternallyVisible (via
getGVALinkageForFunction) on functions while parsing their definitions.

At the point in time when we call getGVALinkageForFunction, we haven't
yet added the body to the function, so we trip this assert.  But as far
as I can tell, this is harmless.

To work around this, we add a new flag to FunctionDecl, "WillHaveBody".

There was other code that was working around the existing assert with a
really awful hack -- this change lets us get rid of that hack.

Reviewers: rsmith, tra

Subscribers: aemerson, cfe-commits

Differential Revision: https://reviews.llvm.org/D25640

llvm-svn: 285410
2016-10-28 16:26:26 +00:00
John McCall b92ab1afd5 Refactor call emission to package the function pointer together with
abstract information about the callee.  NFC.

The goal here is to make it easier to recognize indirect calls and
trigger additional logic in certain cases.  That logic will come in
a later patch; in the meantime, I felt that this was a significant
improvement to the code.

llvm-svn: 285258
2016-10-26 23:46:34 +00:00
Benjamin Kramer 3f515cd795 Fix use-after-scope in ASTContext.
Extend lifetime of ExceptionTypeStorage, as it is referenced by
CanonicalEPI and used outside the block (ExceptionSpec.Exceptions is an
ArrayRef)

Patch by Sam McCall!

Differential Revision: https://reviews.llvm.org/D25983

llvm-svn: 285192
2016-10-26 12:51:45 +00:00
Richard Smith fda59e5851 Implement name mangling proposal for exception specifications from cxx-abi-dev 2016-10-11.
This has the following ABI impact:

 1) Functions whose parameter or return types are non-throwing function pointer
    types have different manglings in c++1z mode from prior modes. This is
    necessary because c++1z permits overloading on the noexceptness of function
    pointer parameter types. A warning is issued for cases that will change
    manglings in c++1z mode.

 2) Functions whose parameter or return types contain instantiation-dependent
    exception specifications change manglings in all modes. This is necessary
    to support overloading on / SFINAE in these exception specifications, which
    a careful reading of the standard indicates has essentially always been
    permitted.

Note that, in order to be affected by these changes, the code in question must
specify an exception specification on a function pointer/reference type that is
written syntactically within the declaration of another function. Such
declarations are very rare, and I have so far been unable to find any code
that would be affected by this. (Note that such things will probably become
more common in C++17, since it's a lot easier to get a noexcept function type
as a function parameter / return type there.)

This change does not affect the set of symbols produced by a build of clang,
libc++, or libc++abi.

llvm-svn: 285150
2016-10-26 01:05:54 +00:00
Kelvin Li 4e325f77a9 Re-apply patch r279045.
llvm-svn: 285066
2016-10-25 12:50:55 +00:00
Erik Verbruggen 490823746a Fix 'unknown documentation command' warning ranges
Warnings generated by -Wdocumentation-unknown-command did only have a
start location, not a full source range. This resulted in only the
"carret" being show in messages, and IDEs highlighting only the single
initial character.

llvm-svn: 285056
2016-10-25 10:06:11 +00:00
Richard Smith afecd83746 Fix bug where one of the cases where we mangle a <bare-unresolved-name> failed
to emit the <template-args> portion. Refactor so that mangleUnresolvedName
actually emits the entire <unresolved-name>, so this mistake is harder to make
again.

llvm-svn: 285022
2016-10-24 20:47:04 +00:00
Richard Smith 4631be7402 Fix mangling of implicit calls to operator-> to only include a single "pt",
rather than including an extra one for each level of 'operator->()' invoked.

llvm-svn: 285015
2016-10-24 20:29:40 +00:00
Richard Smith bac0a0d52b Fix crash if StmtProfile finds a type-dependent member access for which we have
resolved the -> to a call to a specific operator-> function. The particular
test case added here is actually being mishandled: the implicit member access
should not be type-dependent (because it's accessing a non-type-dependent
member of the current instantiation), but calls to a type-dependent operator->
that is a member of the current instantiation would be liable to hit the same
codepath.

llvm-svn: 284999
2016-10-24 18:47:04 +00:00
Richard Smith c7f576fc91 Fix mangling numbers for varargs lambdas; varargs and non-varargs lambdas get
different lambda-sigs, so they should have different counters.

llvm-svn: 284933
2016-10-23 04:53:03 +00:00
Benjamin Kramer 33e9760376 Remove move constructors that are identical to the generated default move ctor.
llvm-svn: 284856
2016-10-21 18:55:07 +00:00
Benjamin Kramer c3f89253ae Retire llvm::alignOf in favor of C++11 alignof.
No functionality change intended.

llvm-svn: 284730
2016-10-20 14:27:22 +00:00
Richard Smith 6609443f2f PR26276: Fix detection of non-cast-expressions as operands of fold-expressions.
llvm-svn: 284684
2016-10-20 00:55:15 +00:00
Richard Smith 304b124a11 [c++1z] Fix corner case where we could create a function type whose canonical type is not actually canonical.
llvm-svn: 284528
2016-10-18 20:13:25 +00:00
Richard Smith 2a2cda58f8 When two function types have equivalent (but distinct) noexcept specifications, create separate type sugar nodes. This is necessary so that substitution into the exception specification will substitute into the correct expression.
llvm-svn: 284519
2016-10-18 19:29:18 +00:00
Richard Smith 391fb8662a [c++1z] Include "noexcept" in builtin function types where appropriate. Fixes
an assertion failure looking up a matching ::operator delete for
__builtin_operator_delete.

llvm-svn: 284458
2016-10-18 07:13:55 +00:00