Commit Graph

2439 Commits

Author SHA1 Message Date
Richard Smith 1879f1069b Disable lambda-capture of decomposition declaration bindings for now, until CWG
agrees on how they're supposed to work.

llvm-svn: 278648
2016-08-15 02:34:23 +00:00
Andrey Bokhanko 1d31e45a8b Fix For pr28288 - Error message in shift of vector values
This fixes an error in type checking of shift of vector values.

Patch by Vladimir Yakovlev.

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

llvm-svn: 278501
2016-08-12 11:22:12 +00:00
Roger Ferrer Ibanez 722a4db198 This patch implements PR#22821.
Taking the address of a packed member is dangerous since the reduced
alignment of the pointee is lost. This can lead to memory alignment
faults in some architectures if the pointer value is dereferenced.

This change adds a new warning to clang emitted when taking the address
of a packed member. A packed member is either a field/data member
declared as attribute((packed)) or belonging to a struct/class
declared as such. The associated flag is -Waddress-of-packed-member.
Conversions (either implicit or via a valid casting) to pointer types
with lower or equal alignment requirements (e.g. void* or char*)
will silence the warning.

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

llvm-svn: 278483
2016-08-12 08:04:13 +00:00
Richard Smith 7873de0cf6 P0217R3: Perform semantic checks and initialization for the bindings in a
decomposition declaration for arrays, aggregate-like structs, tuple-like
types, and (as an extension) for complex and vector types.

llvm-svn: 278435
2016-08-11 22:25:46 +00:00
Justin Lebar b008003aa3 [CUDA] Rename CheckCUDATarget to IsAllowedCUDACall. NFC
Summary:
I want to reuse "CheckCUDAFoo" in a later patch.  Also, I think
IsAllowedCUDACall gets the point across more clearly.

Reviewers: tra

Subscribers: cfe-commits

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

llvm-svn: 278193
2016-08-10 01:09:11 +00:00
Benjamin Kramer 01d3a35aa3 [Sema] Make switch fully covered again.
llvm-svn: 277920
2016-08-06 11:28:20 +00:00
Erik Pilkington f3d77e45c4 [NFC] Silence noisy -Wreturn-type warnings
llvm-svn: 277906
2016-08-06 01:54:50 +00:00
Erik Pilkington 796a3e2bdd [NFC][ObjC Availability] Refactor DiagnoseAvailabilityOfDecl
Differential revision: https://reviews.llvm.org/D23221

llvm-svn: 277887
2016-08-05 22:59:03 +00:00
Erik Pilkington 48c7cc9bc0 Reapply r277058: "[ObjC] Consider availability of context when emitting availability warnings"
llvm-svn: 277175
2016-07-29 17:37:38 +00:00
Erik Pilkington 376789fc73 Revert "[ObjC] Consider availability of context when emitting availability warnings"
Reverting r277058, while I fugure out why it broke internal bots.

This reverts commit e514ffa8b657416c6784bbe6da9f5de19365103d.

llvm-svn: 277070
2016-07-28 22:51:11 +00:00
Erik Pilkington 4f2dd2d4f2 [ObjC] Consider availability of context when emitting availability warnings
This means that a function marked with an availability attribute can safely
refer to a declaration that is greater than the deployment target, but less then
or equal to the context availability without -Wpartial-availability firing.

Differential revision: https://reviews.llvm.org/D22697

llvm-svn: 277058
2016-07-28 22:09:53 +00:00
Yaxun Liu 0bc4b2d337 [OpenCL] Generate opaque type for sampler_t and function call for the initializer
Currently Clang use int32 to represent sampler_t, which have been a source of issue for some backends, because in some backends sampler_t cannot be represented by int32. They have to depend on kernel argument metadata and use IPA to find the sampler arguments and global variables and transform them to target specific sampler type.

This patch uses opaque pointer type opencl.sampler_t* for sampler_t. For each use of file-scope sampler variable, it generates a function call of __translate_sampler_initializer. For each initialization of function-scope sampler variable, it generates a function call of __translate_sampler_initializer.

Each builtin library can implement its own __translate_sampler_initializer(). Since the real sampler type tends to be architecture dependent, allowing it to be initialized by a library function simplifies backend design. A typical implementation of __translate_sampler_initializer could be a table lookup of real sampler literal values. Since its argument is always a literal, the returned pointer is known at compile time and easily optimized to finally become some literal values directly put into image read instructions.

This patch is partially based on Alexey Sotkin's work in Khronos Clang (3d4eec6162).

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

llvm-svn: 277024
2016-07-28 19:26:30 +00:00
Akira Hatanaka 1b07496cea [Sema][ObjC] Compute the nullability of a conditional expression based
on the nullabilities of its operands.

This commit is a follow-up to r276076 and enables
computeConditionalNullability to compute the merged nullability when
the operands are objective-c pointers.

rdar://problem/22074116

llvm-svn: 276696
2016-07-25 21:58:19 +00:00
Richard Smith bdb84f374c P0217R3: Parsing support and framework for AST representation of C++1z
decomposition declarations.

There are a couple of things in the wording that seem strange here:
decomposition declarations are permitted at namespace scope (which we partially
support here) and they are permitted as the declaration in a template (which we
reject).

llvm-svn: 276492
2016-07-22 23:36:59 +00:00
David Majnemer e7287717cb [Sema] Handle errors during rewriteBuiltinFunctionDecl
rewriteBuiltinFunctionDecl can encounter errors when performing
DefaultFunctionArrayLvalueConversion.  These errors were not handled
which led to a null pointer dereference.

This fixes PR28651.

llvm-svn: 276352
2016-07-21 23:03:43 +00:00
Kelvin Li ad9ecbab42 [OpenMP] Allow negative lower bound in array sections based on pointers
OpenMP 4.5 removed the restriction that array section lower bound must be non negative.
This change is to allow negative values for array section based on pointers.
For array section based on array type there is still a restriction: "The array section must be a subset of the original array."

Patch by David S.

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

llvm-svn: 276177
2016-07-20 20:45:29 +00:00
Akira Hatanaka 73118fd10e [Sema] Compute the nullability of a conditional expression based on the
nullabilities of its operands.

This patch defines a function to compute the nullability of conditional
expressions, which enables Sema to precisely detect implicit conversions
of nullable conditional expressions to nonnull pointers.

rdar://problem/25166556

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

llvm-svn: 276076
2016-07-20 01:48:11 +00:00
Bruno Cardoso Lopes d9b7dfe4a4 [Sema] Create a separate group for incompatible function pointer warning
Give incompatible function pointer warning its own diagnostic group
but still leave it as a subgroup of incompatible-pointer-types. This is in
preparation to promote -Wincompatible-function-pointer-types to error on
darwin.

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

rdar://problem/12907612

llvm-svn: 275907
2016-07-18 20:37:06 +00:00
Mehdi Amini 9670f847b8 [NFC] Header cleanup
Summary: Removed unused headers, replaced some headers with forward class declarations

Patch by: Eugene <claprix@yandex.ru>

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

llvm-svn: 275882
2016-07-18 19:02:11 +00:00
Erik Pilkington 29099ded0c [ObjC] Implement @available in the Parser and AST
This patch adds a new AST node: ObjCAvailabilityCheckExpr, and teaches the
Parser and Sema to generate it. This node represents an availability check of
the form:

  @available(macos 10.10, *);

Which will eventually compile to a runtime check of the host's OS version. This
is the first patch of the feature I proposed here:
http://lists.llvm.org/pipermail/cfe-dev/2016-July/049851.html

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

llvm-svn: 275654
2016-07-16 00:35:23 +00:00
Roger Ferrer Ibanez 58b8e483f0 Reverting 275417
This change has triggered unexpected failures.

llvm-svn: 275462
2016-07-14 20:05:30 +00:00
Roger Ferrer Ibanez 585ea9ddce Diagnose taking address and reference binding of packed members
This patch implements PR#22821.

Taking the address of a packed member is dangerous since the reduced
alignment of the pointee is lost. This can lead to memory alignment
faults in some architectures if the pointer value is dereferenced.

This change adds a new warning to clang emitted when taking the address
of a packed member. A packed member is either a field/data member
declared as attribute((packed)) or belonging to a struct/class
declared as such. The associated flag is -Waddress-of-packed-member.
Conversions (either implicit or via a valid casting) to pointer types
with lower or equal alignment requirements (e.g. void* or char*)
silence the warning.

This change also adds a new error diagnostic when the user attempts to
bind a reference to a packed member, regardless of the alignment.

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

llvm-svn: 275417
2016-07-14 14:10:43 +00:00
Anastasia Stulova 4d85003964 [OpenCL] Improved diagnostics of OpenCL types.
- Changes diagnostics for Blocks to be implicitly
const qualified OpenCL v2.0 s6.12.5.

 - Added and unified diagnostics of some OpenCL special types:
blocks, images, samplers, pipes. These types are intended for use
with the OpenCL builtin functions only and, therefore, most regular
uses are not allowed including assignments, arithmetic operations,
pointer dereferencing, etc.

Review: http://reviews.llvm.org/D21989
llvm-svn: 275061
2016-07-11 13:46:02 +00:00
Bruno Cardoso Lopes 2ebe18b609 [SemaExpr] Support assignments from vector to scalars with same size
Before r266366, clang used to support constructs like:

  typedef __attribute__((vector_size(8))) double float64x1_t;
  typedef __attribute__((vector_size(16))) double float64x2_t;
  float64x1_t vget_low_f64(float64x2_t __p0);

  double y = 3.0 + vget_low_f64(v);

But it would reject:

  double y = vget_low_f64(v) + 3.0;

It also always rejected assignments:

  double y = vget_low_f64(v);

This patch: (a) revivies the behavior of `3.0 + vget_low_f64(v)` prior to
r266366, (b) add support for `vget_low_f64(v) + 3.0` and (c) add support for
assignments.

These vector semantics have never really been tied up but it seems
odd that we used to support some binop froms but do not support
assignment. If we did support scalar for the purposes of arithmetic, we
should probably be able to reinterpret as scalar for the purposes of
assignment too.

Differential Revision: http://reviews.llvm.org/D21700

rdar://problem/26093791

llvm-svn: 274646
2016-07-06 18:05:23 +00:00
Manman Ren ebe8cf55ac C++14 init-capture: error out instead of crashing.
When we have template arguments, we have a function and a pattern, the variable
in init-capture belongs to the pattern decl when checking if the lhs of
"max = current" is modifiable:
  auto find = [max = init](auto current) {
    max = current;
  };

In function isReferenceToNonConstCapture, we handle the case where the decl
context for the variable is not part of the current context.

Instead of crashing, we emit an error message:
cannot assign to a variable captured by copy in a non-mutable lambda

rdar://26997922

llvm-svn: 274392
2016-07-01 22:27:16 +00:00
Richard Smith cc4bb63351 PR28373: fix crash-on-invalid if the condition of an if-statement fails typo-correction.
llvm-svn: 274260
2016-06-30 18:36:34 +00:00
Richard Smith 80a4702d02 Mark inheriting constructors as deleted if the corresponding defaulted default
constructor would be; this is effectively required by P0136R1. This has the
effect of exposing the validity of the base class initialization steps to
SFINAE checks.

llvm-svn: 274088
2016-06-29 01:10:27 +00:00
Richard Smith 5179eb7821 P0136R1, DR1573, DR1645, DR1715, DR1736, DR1903, DR1941, DR1959, DR1991:
Replace inheriting constructors implementation with new approach, voted into
C++ last year as a DR against C++11.

Instead of synthesizing a set of derived class constructors for each inherited
base class constructor, we make the constructors of the base class visible to
constructor lookup in the derived class, using the normal rules for
using-declarations.

For constructors, UsingShadowDecl now has a ConstructorUsingShadowDecl derived
class that tracks the requisite additional information. We create shadow
constructors (not found by name lookup) in the derived class to model the
actual initialization, and have a new expression node,
CXXInheritedCtorInitExpr, to model the initialization of a base class from such
a constructor. (This initialization is special because it performs real perfect
forwarding of arguments.)

In cases where argument forwarding is not possible (for inalloca calls,
variadic calls, and calls with callee parameter cleanup), the shadow inheriting
constructor is not emitted and instead we directly emit the initialization code
into the caller of the inherited constructor.

Note that this new model is not perfectly compatible with the old model in some
corner cases. In particular:
 * if B inherits a private constructor from A, and C uses that constructor to
   construct a B, then we previously required that A befriends B and B
   befriends C, but the new rules require A to befriend C directly, and
 * if a derived class has its own constructors (and so its implicit default
   constructor is suppressed), it may still inherit a default constructor from
   a base class

llvm-svn: 274049
2016-06-28 19:03:57 +00:00
David Majnemer 59f7792136 Use more ArrayRefs
No functional change is intended, just a small refactoring.

llvm-svn: 273647
2016-06-24 04:05:48 +00:00
Richard Smith b130fe7d31 Implement p0292r2 (constexpr if), a likely C++1z feature.
llvm-svn: 273602
2016-06-23 19:16:49 +00:00
Richard Smith 03a4aa3d00 Re-commit r273548, reverted in r273589, with a fix to not produce
-Wfor-loop-analysis warnings for a for-loop with a condition variable. In such
a case, the loop condition variable is modified on each iteration of the loop
by definition.

Original commit message:

Rearrange condition handling so that semantic checks on a condition variable
are performed before the other substatements of the construct are parsed,
rather than deferring them until the end. This allows better error recovery
from semantic errors in the condition, improves diagnostic order, and is a
prerequisite for C++17 constexpr if.

llvm-svn: 273600
2016-06-23 19:02:52 +00:00
Peter Collingbourne b77ebd749a Revert r273548, "Rearrange condition handling so that semantic checks on a condition variable"
as it caused a regression in -Wfor-loop-analysis.

llvm-svn: 273589
2016-06-23 18:11:15 +00:00
Richard Smith 19f877c3f2 Rearrange condition handling so that semantic checks on a condition variable
are performed before the other substatements of the construct are parsed,
rather than deferring them until the end. This allows better error recovery
from semantic errors in the condition, improves diagnostic order, and is a
prerequisite for C++17 constexpr if.

llvm-svn: 273548
2016-06-23 08:41:20 +00:00
Tim Shen 4a05bb8d8d Re-commit "[Temporary] Add an ExprWithCleanups for each C++ MaterializeTemporaryExpr."
Since D21243 fixes relative clang-tidy tests.

This reverts commit a71d9fbd41e99def9159af2b01ef6509394eaeed.

llvm-svn: 273312
2016-06-21 20:29:17 +00:00
Erik Pilkington 71a7d912dc [Sema] Only define function as move assignment when needed
Fixes PR27941, a crash on invalid.

Differential revision: http://reviews.llvm.org/D20923

llvm-svn: 273193
2016-06-20 20:04:15 +00:00
Alexey Bataev 61deb4dadc Revert accidential "[MSVC] Late parsing of in-class defined member functions in template"
This reverts commit 0253605771b8bd9d414aba74fe2742c730d6fd1a.

llvm-svn: 272776
2016-06-15 11:24:54 +00:00
Alexey Bataev 86e786bd17 [MSVC] Late parsing of in-class defined member functions in template
classes.

MSVC actively uses unqualified lookup in dependent bases, lookup at the
instantiation point (non-dependent names may be resolved on things
declared later) etc. and all this stuff is the main cause of
incompatibility between clang and MSVC.

Clang tries to emulate MSVC behavior but it may fail in many cases.
clang could store lexed tokens for member functions definitions within
ClassTemplateDecl for later parsing during template instantiation.

It will allow resolving many possible issues with lookup in dependent
base classes and removing many already existing MSVC-specific
hacks/workarounds from the clang code.

llvm-svn: 272774
2016-06-15 11:19:39 +00:00
Yaxun Liu 18e3fd3ad6 [OpenCL] Enable -fblocks by default for OpenCL 2.0 and above.
Reviewed as part of http://reviews.llvm.org/D20444

llvm-svn: 272720
2016-06-14 21:43:01 +00:00
Roger Ferrer Ibanez 985c0c274b Reverting "Warn when taking address of a packed member"
This new diagnostic is causing some false positives that have to be addressed.

This reverts commit 272552

llvm-svn: 272653
2016-06-14 11:20:07 +00:00
Serge Pavlov b82a9401df Detect recursive default argument definition
If definition of default function argument uses itself, clang crashed,
because corresponding function parameter is not associated with the default
argument yet. With this fix clang emits appropriate error message.

This change fixes PR28105.

Differential Revision: http://reviews.llvm.org/D21301

llvm-svn: 272623
2016-06-14 02:55:56 +00:00
Roger Ferrer Ibanez ac6617b288 Warn when taking address of a packed member
This patch implements PR#22821.

Taking the address of a packed member is dangerous since the reduced
alignment of the pointee is lost. This can lead to memory alignment
faults in some architectures if the pointer value is dereferenced.

This change adds a new warning to clang emitted when taking the address
of a packed member. A packed member is either a field/data member
declared as attribute((packed)) or belonging to a struct/class
declared as such. The associated flag is -Waddress-of-packed-member

Differential Revision: http://reviews.llvm.org/D20561

llvm-svn: 272552
2016-06-13 15:41:40 +00:00
Tim Shen 17b3deeff3 Revert "[Temporary] Add an ExprWithCleanups for each C++ MaterializeTemporaryExpr."
This reverts r272296, since there are clang-tidy failures that appear to
be caused by this change.

llvm-svn: 272310
2016-06-09 21:13:39 +00:00
Tim Shen f120a7b6a3 [Temporary] Add an ExprWithCleanups for each C++ MaterializeTemporaryExpr.
These ExprWithCleanups are added for holding a RunCleanupsScope not
for destructor calls; rather, they are for lifetime marks. This requires
ExprWithCleanups to keep a bit to indicate whether it have cleanups with
side effects (e.g. dtor calls).

Differential Revision: http://reviews.llvm.org/D20498

llvm-svn: 272296
2016-06-09 19:54:46 +00:00
George Burgess IV beca4a3338 [Sema] Teach CheckPlaceholderExpr about unaddressable functions.
Given the following C++:

```
void foo();
void foo() __attribute__((enable_if(false, "")));

bool bar() {
  auto P = foo;
  return P == foo;
}
```

We'll currently happily (and correctly) resolve `foo` to the `foo`
overload without `enable_if` when assigning to `P`. However, we'll
complain about an ambiguous overload on the `P == foo` line, because
`Sema::CheckPlaceholderExpr` doesn't recognize that there's only one
`foo` that could possibly work here.

This patch teaches `Sema::CheckPlaceholderExpr` how to properly deal
with such cases.

Grepping for other callers of things like
`Sema::ResolveAndFixSingleFunctionTemplateSpecialization`, it *looks*
like this is the last place that needed to be fixed up. If I'm wrong,
I'll see if there's something we can do that beats what amounts to
whack-a-mole with bugs.

llvm-svn: 272080
2016-06-08 00:34:22 +00:00
Alexey Bataev 7ace49dff1 [OPENMP] Pass scalar firstprivate vars by value.
For better performance and to unify code with offloading part we pass
scalar firstprivate values by value, instead of by reference. It will
remove some extra copying operations.

llvm-svn: 269751
2016-05-17 08:55:33 +00:00
Andrey Bokhanko 45d413260e [MSVC] Implementation of __unaligned as a proper type qualifier
This patch implements __unaligned (MS extension) as a proper type qualifier
(before that, it was implemented as an ignored attribute).

It also fixes PR27367 and PR27666.

Differential Revision: http://reviews.llvm.org/D20103

llvm-svn: 269220
2016-05-11 18:38:21 +00:00
Nemanja Ivanovic bb1ea2d613 Enable support for __float128 in Clang and enable it on pertinent platforms
This patch corresponds to reviews:
http://reviews.llvm.org/D15120
http://reviews.llvm.org/D19125

It adds support for the __float128 keyword, literals and target feature to
enable it. Based on the latter of the two aforementioned reviews, this feature
is enabled on Linux on i386/X86 as well as SystemZ.
This is also the second attempt in commiting this feature. The first attempt
did not enable it on required platforms which caused failures when compiling
type_traits with -std=gnu++11.

If you see failures with compiling this header on your platform after this
commit, it is likely that your platform needs to have this feature enabled.

llvm-svn: 268898
2016-05-09 08:52:33 +00:00
Olivier Goffart 63a2083be9 Fix spurious warnings about unused private field
If the address of a field is taken as a pointer to member, we should
not warn that the field is not used.

Normaly, yse of fields are done from MemberExpr, but in case of pointer to
member, it is in a DeclRefExpr

Differential Revision: http://reviews.llvm.org/D20054

llvm-svn: 268895
2016-05-09 07:09:51 +00:00
Nico Weber 2801d32c07 Revert r268727, it caused PR27666.
llvm-svn: 268736
2016-05-06 14:34:29 +00:00
Andrey Bokhanko ba0d7540e3 [MSVC] Implementation of __unaligned as a proper type qualifier
This patch implements __unaligned (MS extension) as a proper type qualifier
(before that, it was implemented as an ignored attribute).

It also fixes PR27367.

Differential Revision: http://reviews.llvm.org/D19654

llvm-svn: 268727
2016-05-06 11:47:55 +00:00
Richard Smith 6739a10cec [modules] Enforce the rules that an explicit or partial specialization must be
declared before it is used. Because we don't use normal name lookup to find
these, the normal code to filter out non-visible names from name lookup results
does not apply.

llvm-svn: 268585
2016-05-05 00:56:12 +00:00
Reid Kleckner f463a8a424 Avoid -Wshadow warnings about constructor parameters named after fields
Usually these parameters are used solely to initialize the field in the
initializer list, and there is no real shadowing confusion.

There is a new warning under -Wshadow called
-Wshadow-field-in-constructor-modified. It attempts to find
modifications of such constructor parameters that probably intended to
modify the field.

It has some false negatives, though, so there is another warning group,
-Wshadow-field-in-constructor, which always warns on this special case.
For users who just want the old behavior and don't care about these fine
grained groups, we have a new warning group called -Wshadow-all that
activates everything.

Fixes PR16088.

Reviewers: rsmith

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D18271

llvm-svn: 267957
2016-04-29 00:37:43 +00:00
Vassil Vassilev 928c8254a9 Reland r267691 fixing PR27535.
llvm-svn: 267882
2016-04-28 14:13:28 +00:00
Nico Weber 3a94763101 Revert r267691, it caused PR27535.
llvm-svn: 267744
2016-04-27 17:26:08 +00:00
Vassil Vassilev a4d7d783d0 [modules] Fix Decl's Used invariant.
The Decl::isUsed has a value for every decl. In non-module builds it is very
difficult (but possible) to break this invariant but when we walk up the redecl
chain we find the neccessary information.

When deserializing the decls from a module it is much more difficult to update
correctly this invariant. The patch centralizes the information whether a decl
is used in the canonical decl marking the entire entity as being used.

Fixes https://llvm.org/bugs/show_bug.cgi?id=27401

Patch by Cristina Cristescu and me.

Thanks to Richard Smith who helped to debug and understand the issue!

Reviewed by Richard Smith.

llvm-svn: 267691
2016-04-27 10:46:06 +00:00
Nemanja Ivanovic d7d45bf8ce Revert 266186 as it breaks anything that includes type_traits on some platforms
Since this patch provided support for the __float128 type but disabled it
on all platforms by default, some platforms can't compile type_traits with
-std=gnu++11 since there is a specialization with __float128.
This reverts the patch until D19125 is approved (i.e. we know which platforms
need this support enabled).

llvm-svn: 266460
2016-04-15 18:04:13 +00:00
Nico Weber 917fc9d7cb Revert r266415, it broke parsing SDK headers (PR27367).
llvm-svn: 266431
2016-04-15 14:35:06 +00:00
Andrey Bokhanko f7fa634887 [MSVC Compat] Implementation of __unaligned (MS extension) as a type qualifier
This patch implements __unaligned as a type qualifier; before that, it was
modeled as an attribute. Proper mangling of __unaligned is implemented as well.
Some OpenCL code/tests are tangenially affected, as they relied on existing
number and sizes of type qualifiers.

Differential Revision: http://reviews.llvm.org/D18596

llvm-svn: 266415
2016-04-15 08:03:51 +00:00
Reid Kleckner e1a16467a3 In vector comparisons, handle scalar LHS just as we handle scalar RHS
Summary: Fixes PR27258

Reviewers: rsmith

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D19123

llvm-svn: 266366
2016-04-14 21:03:38 +00:00
Nemanja Ivanovic 50f29e06a1 Enable support for __float128 in Clang
This patch corresponds to review:
http://reviews.llvm.org/D15120

It adds support for the __float128 keyword, literals and a target feature to
enable it. This support is disabled by default on all targets and any target
that has support for this type is free to add it.

Based on feedback that I've received from target maintainers, this appears to
be the right thing for most targets. I have not heard from the maintainers of
X86 which I believe supports this type. I will subsequently investigate the
impact of enabling this on X86.

llvm-svn: 266186
2016-04-13 09:49:45 +00:00
Alexey Bader b62f14400f [OpenCL] Move OpenCLImageTypes.def from clangAST to clangBasic library.
Putting OpenCLImageTypes.def to clangAST library violates layering requirement: "It's not OK for a Basic/ header to include an AST/ header".
This fixes the modules build.

Differential revision: http://reviews.llvm.org/D18954
Reviewers: Richard Smith, Vassil Vassilev.

llvm-svn: 266180
2016-04-13 08:33:41 +00:00
Yaxun Liu a1a87adf59 PR19957: [OpenCL] Incorrectly accepts implicit address space conversion with ternary operator.
Generates addrspacecast instead of bitcast for ternary operator when necessary, and diagnose ternary operator with incompatible second and third operands.

https://llvm.org/bugs/show_bug.cgi?id=19957

Differential Revision: http://reviews.llvm.org/D17412

llvm-svn: 266111
2016-04-12 19:43:36 +00:00
Alexey Bader 954ba21f85 [OpenCL] Complete image types support.
I. Current implementation of images is not conformant to spec in the following points:
  1. It makes no distinction with respect to access qualifiers and therefore allows to use images with different access type interchangeably. The following code would compile just fine:

        void write_image(write_only image2d_t img);
        kernel void foo(read_only image2d_t img) { write_image(img); } // Accepted code

     which is disallowed according to s6.13.14.

  2. It discards access qualifier on generated code, which leads to generated code for the above example:

        call void @write_image(%opencl.image2d_t* %img);

     In OpenCL2.0 however we can have different calls into write_image with read_only and wite_only images.
     Also generally following compiler steps have no easy way to take different path depending on the image access: linking to the right implementation of image types, performing IR opts and backend codegen differently.

  3. Image types are language keywords and can't be redeclared s6.1.9, which can happen currently as they are just typedef names.
  4. Default access qualifier read_only is to be added if not provided explicitly.

II. This patch corrects the above points as follows:
  1. All images are encapsulated into a separate .def file that is inserted in different points where image handling is required. This avoid a lot of code repetition as all images are handled the same way in the code with no distinction of their exact type.
  2. The Cartesian product of image types and image access qualifiers is added to the builtin types. This simplifies a lot handling of access type mismatch as no operations are allowed by default on distinct Builtin types. Also spec intended access qualifier as special type qualifier that are combined with an image type to form a distinct type (see statement above - images can't be created w/o access qualifiers).
  3. Improves testing of images in Clang.

Author: Anastasia Stulova
Reviewers: bader, mgrang.
Subscribers: pxli168, pekka.jaaskelainen, yaxunl.
Differential Revision: http://reviews.llvm.org/D17821

llvm-svn: 265783
2016-04-08 13:40:33 +00:00
Dmitry Polukhin 0b0da296e6 [OPENMP] Parsing and Sema support for 'omp declare target' directive
Add parsing, sema analysis for 'declare target' construct for OpenMP 4.0
(4.5 support will be added in separate patch).

The declare target directive specifies that variables, functions (C, C++
and Fortran), and subroutines (Fortran) are mapped to a device. The declare
target directive is a declarative directive. In Clang declare target is
implemented as implicit attribute for the declaration.

The syntax of the declare target directive is as follows:

 #pragma omp declare target
 declarations-definition-seq
 #pragma omp end declare target

Based on patch from Michael Wong http://reviews.llvm.org/D15321

llvm-svn: 265530
2016-04-06 11:38:59 +00:00
George Burgess IV 6ae936cbf2 [Sema] Delete FIXME that has been fixed. NFC.
llvm-svn: 265341
2016-04-04 19:44:16 +00:00
George Burgess IV 21d3bffe29 [Sema] Fix PR27122: ICE with enable_if+ill-formed call.
In some cases, when we encounter a direct function call with an
incorrect number of arguments, we'll emit a diagnostic, and pretend that
the call to the function was valid. For example, in C:

int foo();
int a = foo(1);

Prior to this patch, we'd get an ICE if foo had an enable_if attribute,
because CheckEnableIf assumes that the number of arguments it gets
passed is valid for the function it's passed. Now, we check that the
number of args looks valid prior to checking enable_if conditions.

This fix was not done inside of CheckEnableIf because the problem
presently can only occur in one caller of CheckEnableIf (ActOnCallExpr).
Additionally, checking inside of CheckEnableIf would make us emit
multiple diagnostics for the same error (one "enable_if failed", one
"you gave this function the wrong number of arguments"), which seems
worse than just complaining about the latter.

llvm-svn: 264975
2016-03-31 00:16:25 +00:00
Richard Smith 0e32c5283a Don't warn on "use" of undefined inline function that isn't actually an ODR
use. In order for this to fire, the function needed to be a templated function
marked 'constexpr' and declared but not defined. This weird pattern appears in
libstdc++'s alloc_traits.h.

llvm-svn: 264471
2016-03-25 22:29:27 +00:00
Faisal Vali 084c912499 [NFC] Delete an unused function parameter from a static function
llvm-svn: 264170
2016-03-23 17:39:51 +00:00
Faisal Vali dc6b596ebb [Cxx1z] Implement Lambda Capture of *this by Value as [=,*this] (P0018R3)
Implement lambda capture of *this by copy.
For e.g.:
struct A {

  int d = 10;
  auto foo() { return [*this] (auto a) mutable { d+=a; return d; }; }

};

auto L = A{}.foo(); // A{}'s lifetime is gone.

// Below is still ok, because *this was captured by value.
assert(L(10) == 20);
assert(L(100) == 120);

If the capture was implicit, or [this] (i.e. *this was captured by reference), this code would be otherwise undefined.

Implementation Strategy:
  - amend the parser to accept *this in the lambda introducer
  - add a new king of capture LCK_StarThis
  - teach Sema::CheckCXXThisCapture to handle by copy captures of the
    enclosing object (i.e. *this)
  - when CheckCXXThisCapture does capture by copy, the corresponding 
    initializer expression for the closure's data member 
    direct-initializes it thus making a copy of '*this'.
  - in codegen, when assigning to CXXThisValue, if *this was captured by 
    copy, make sure it points to the corresponding field member, and
    not, unlike when captured by reference, what the field member points
    to.
  - mark feature as implemented in svn

Much gratitude to Richard Smith for his carefully illuminating reviews!   

llvm-svn: 263921
2016-03-21 09:25:37 +00:00
Manman Ren 073db02476 Add TreatUnavailableAsInvalid for the verification-only mode in InitListChecker.
Given the following test case:
typedef struct {
  const char *name;
  id field;
} Test9;
extern void doSomething(Test9 arg);
void test9() {
  Test9 foo2 = {0, 0};
  doSomething(foo2);
}
With a release compiler, we don't emit any message and silently ignore the
variable "foo2". With an assert compiler, we get an assertion failure.

The root cause —————————————
Back in r140457 we gave InitListChecker a verification-only mode, and will use
CanUseDecl instead of DiagnoseUseOfDecl for verification-only mode.

These two functions handle unavailable issues differently:
In Sema::CanUseDecl, we say the decl is invalid when the Decl is unavailable and
the current context is available.

In Sema::DiagnoseUseOfDecl, we say the decl is usable by ignoring the return
code of DiagnoseAvailabilityOfDecl

So with an assert build, we will hit an assertion in diagnoseListInit
assert(DiagnoseInitList.HadError() &&
       "Inconsistent init list check result.");

The fix -------------------
If we follow what is implemented in CanUseDecl and treat Decls with
unavailable issues as invalid, the variable decl of “foo2” will be marked as
invalid. Since unavailable checking is processed in delayed diagnostics
(r197627), we will silently ignore the diagnostics when we find out that
the variable decl is invalid.

We add a flag "TreatUnavailableAsInvalid" for the verification-only mode.
For overload resolution, we want to say decls with unavailable issues are
invalid; but for everything else, we should say they are valid and
emit diagnostics. Depending on the value of the flag, CanUseDecl
can return different values for unavailable issues.

rdar://23557300
Differential Revision: http://reviews.llvm.org/D15314

llvm-svn: 263149
2016-03-10 18:53:19 +00:00
Aaron Ballman 0bcd6c1b18 Implement support for [[maybe_unused]] in C++1z that is based off existing support for unused, and treat it as an extension pre-C++1z. This also means extending the existing unused attribute so that it can be placed on an enum and enumerator, in addition to the other subjects.
llvm-svn: 263025
2016-03-09 16:48:08 +00:00
Duncan P. N. Exon Smith 5d6790c746 Sema: Treat 'strict' availability flag like unavailable
This is a follow-up to r261512, which made the 'strict' availability
attribute flag behave like 'unavailable'.  However, that fix was
insufficient.  The following case would (erroneously) error when the
deployment target was older than 10.9:

    struct __attribute__((availability(macosx,strict,introduced=10.9))) A;
    __attribute__((availability(macosx,strict,introduced=10.9))) void f(A*);

The use of A* in the argument list for f is valid here, since f and A
have the same availability.

The fix is to return AR_Unavailable from DeclBase::getAvailability
instead of AR_NotYetIntroduced.  This also reverts the special handling
added in r261163, instead relying on the well-tested logic for
AR_Unavailable.

rdar://problem/23791325

llvm-svn: 262915
2016-03-08 06:12:54 +00:00
Richard Trieu 2334a30e15 Add null check to diagnostic path for lambda captures.
Previously, the failed capture of a variable in nested lambdas may crash when
the lambda pointer is null.  Only give the note if a location can be retreived
from the lambda pointer.

llvm-svn: 262765
2016-03-05 04:04:57 +00:00
Alexey Bataev c5b1d320b8 [OPENMP 4.0] Codegen for 'declare reduction' construct.
Emit function for 'combiner' part of 'declare reduction' construct and
'initialilzer' part, if any.

llvm-svn: 262699
2016-03-04 09:22:22 +00:00
Alexey Bataev 94a4f0cb5f [OPENMP 4.0] Initial support for 'omp declare reduction' construct.
Add parsing, sema analysis and serialization/deserialization for 'declare reduction' construct.
User-defined reductions are defined as

#pragma omp declare reduction( reduction-identifier : typename-list : combiner ) [initializer ( initializer-expr )]
These custom reductions may be used in 'reduction' clauses of OpenMP constructs. The combiner specifies how partial results can be combined into a single value. The
combiner can use the special variable identifiers omp_in and omp_out that are of the type of the variables being reduced with this reduction-identifier. Each of them will
denote one of the values to be combined before executing the combiner. It is assumed that the special omp_out identifier will refer to the storage that holds the resulting
combined value after executing the combiner.
As the initializer-expr value of a user-defined reduction is not known a priori the initializer-clause can be used to specify one. Then the contents of the initializer-clause
will be used as the initializer for private copies of reduction list items where the omp_priv identifier will refer to the storage to be initialized. The special identifier
omp_orig can also appear in the initializer-clause and it will refer to the storage of the original variable to be reduced.
Differential Revision: http://reviews.llvm.org/D11182

llvm-svn: 262582
2016-03-03 05:21:39 +00:00
Xiuli Pan 89307aa3e9 [OpenCL] Add Sema checks for OpenCL 2.0 block
Summary:
Add Sema checks for opencl 2.0 new features: Block.
This patch is partitioned from http://reviews.llvm.org/D16047

Reviewers: Anastasia

Subscribers: pekka.jaaskelainen, cfe-commits

Differential Revision: http://reviews.llvm.org/D17436

llvm-svn: 261719
2016-02-24 04:29:36 +00:00
Aaron Ballman 558995c967 Amends r252104 to evaluate the controlling expression in an unevaluated context. This eliminates false-positive diagnostics about null pointer dereferences (etc) in the controlling expression.
llvm-svn: 261669
2016-02-23 18:55:15 +00:00
Manman Ren d8039df523 Addressing review comments for r261163.
Use "strict" instead of "nopartial". Also make strictly not-introduced
share the same diagnostics as Obsolete and Unavailable.

rdar://23791325

llvm-svn: 261512
2016-02-22 04:47:24 +00:00
Richard Trieu 54f82bfb80 Fix my typo from r261278
llvm-svn: 261285
2016-02-19 00:15:50 +00:00
Richard Trieu faca2d83b1 Add -Wcomma warning to Clang.
-Wcomma will detect and warn on most uses of the builtin comma operator.  It
currently whitelists the first and third statements of the for-loop.  For other
cases, the warning can be silenced by casting the first operand of the comma
operator to void.

Differential Revision: http://reviews.llvm.org/D3976

llvm-svn: 261278
2016-02-18 23:58:40 +00:00
Manman Ren b636b904c2 Add 'nopartial' qualifier for availability attributes.
An optional nopartial can be placed after the platform name.
int bar() __attribute__((availability(macosx,nopartial,introduced=10.12))

When deploying back to a platform version prior to when the declaration was
introduced, with 'nopartial', Clang emits an error specifying that the function
is not introduced yet; without 'nopartial', the behavior stays the same: the
declaration is `weakly linked`.

A member is added to the end of AttributeList to save the location of the
'nopartial' keyword. A bool member is added to AvailabilityAttr.

The diagnostics for 'nopartial' not-yet-introduced is handled in the same way as
we handle unavailable cases.

Reviewed by Doug Gregor and Jordan Rose.

rdar://23791325

llvm-svn: 261163
2016-02-17 22:05:48 +00:00
David Majnemer 2eb74e278d Correct more typos in conditional expressions
We didn't correctly handle some edge cases, causing us to bail out
before correcting all the typos.

llvm-svn: 261109
2016-02-17 17:19:00 +00:00
Anastasia Stulova 5c1a2c5d3e [OpenCL] Added half type literal with suffix h.
OpenCL Extension v1.2 s9.5 allows half precision floating point
type literals with suffices h or H when cl_khr_fp16 is enabled.

Example:  half x = 1.0h;

Patch by Liu Yaxun (Sam)!

Differential Revision: http://reviews.llvm.org/D16865

llvm-svn: 261084
2016-02-17 11:34:37 +00:00
Bob Wilson f5c53b859b [Sema] More changes to fix Objective-C fallout from r249995.
This is a follow-up to PR26085. That was fixed in r257710 but the testcase
there was incomplete. There is a related issue where the overload resolution
for Objective-C incorrectly picks a method that is not valid without a
bridge cast. The call to Sema::CheckSingleAssignmentConstraints that was
added to SemaOverload.cpp's IsStandardConversion() function does not catch
that case and reports that the method is Compatible even when it is not.

The root cause here is that various Objective-C-related functions in Sema
do not consistently return a value to indicate whether there was an error.
This was fine in the past because they would report diagnostics when needed,
but r257710 changed them to suppress reporting diagnostics when checking
during overload resolution.

This patch adds a new ACR_error result to the ARCConversionResult enum and
updates Sema::CheckObjCARCConversion to return that value when there is an
error. Most of the calls to that function do not check the return value,
so adding this new result does not affect them. The one exception is in
SemaCast.cpp where it specifically checks for ACR_unbridged, so that is
also OK. The call in Sema::CheckSingleAssignmentConstraints can then check
for an ACR_okay result and identify assignments as Incompatible. To
preserve the existing behavior, it only changes the return value to
Incompatible when the new Diagnose argument (from r257710) is false.

Similarly, the CheckObjCBridgeRelatedConversions and
ConversionToObjCStringLiteralCheck need to identify when an assignment is
Incompatible. Those functions already return appropriate values but they
need some fixes related to the new Diagnose argument.

llvm-svn: 260787
2016-02-13 01:41:41 +00:00
Alexey Bataev 4244be25bd [OPENMP] Rename OMPCapturedFieldDecl to OMPCapturedExprDecl, NFC.
OMPCapturedExprDecl allows caopturing not only of fielddecls, but also
other expressions. It also allows to simplify codegen for several
clauses.

llvm-svn: 260492
2016-02-11 05:35:55 +00:00
Alexey Bataev 90c228f0ba [OPENMP 4.5] Ccapture/codegen of private non-static data members.
OpenMP 4.5 introduces privatization of non-static data members of current class in non-static member functions.
To correctly handle such kind of privatization a new (pseudo)declaration VarDecl-based node is added. It allows to reuse an existing code for capturing variables in Lambdas/Block/Captured blocks of code for correct privatization and codegen.

llvm-svn: 260077
2016-02-08 09:29:13 +00:00
Alexey Bataev 31300ed0a5 [OPENMP 4.0] Fixed support of array sections/array subscripts.
Codegen for array sections/array subscripts worked only for expressions with arrays as base. Patch fixes codegen for bases with pointer/reference types.

llvm-svn: 259776
2016-02-04 11:27:03 +00:00
Douglas Gregor 0fc3a00168 [Sema debugger support] Require non-void types to be complete in unknown-anytype casts.
When performing a cast from an __unknown_anytype function call to a
non-void type, we need to make sure that type is complete. Fixes
rdar://problem/23959960.

llvm-svn: 259681
2016-02-03 19:13:08 +00:00
Alexey Bataev 41ed6b7aba Allow capture typedefs/type aliases for VLAs in lambdas/captured statements chain.
Previous it was allowed to capture VLAs/types with arrays of runtime bounds only inside the first lambda/capture statement in stack. Patch allows to capture these typedefs implicitly in chains of lambdas/captured statements.

llvm-svn: 258669
2016-01-25 07:06:23 +00:00
Alexey Bataev 93a546a326 Fix crash for typedefs for arrays of runtime bounds in Lambdas/Captured Statements, used in sizeof() expression only.
llvm-svn: 258396
2016-01-21 12:54:48 +00:00
Alexey Bataev 48c0bfb99f [OPENMP 4.5] Allow to use non-static data members in non-static member functions in 'private' clause.
OpenMP 4.5 allows to use non-static members of current class in non-static member functions in 'private' clause. Patch adds initial support for privatizing data members.

llvm-svn: 258299
2016-01-20 09:07:54 +00:00
Justin Lebar 6644e366b0 [CUDA] Bail, rather than crash, on va_arg in device code.
Reviewers: tra

Subscribers: echristo, jhen, cfe-commits

Differential Revision: http://reviews.llvm.org/D16331

llvm-svn: 258264
2016-01-20 00:27:00 +00:00
Alexey Bataev d51e9933b6 [X86] Support 'interrupt' attribute for x86
This attribute may be attached to a function definition and instructs the backend to generate appropriate function entry/exit code so that
it can be used directly as an interrupt handler.
The IRET instruction, instead of the RET instruction, is used to return from interrupt or exception handlers. All registers, except for the EFLAGS register which is restored by the IRET instruction, are preserved by the compiler.
Any interruptible-without-stack-switch code must be compiled with -mno-red-zone since interrupt handlers can and will, because of the hardware design, touch
the red zone.

interrupt handler must be declared with a mandatory pointer argument:
struct interrupt_frame;

__attribute__ ((interrupt))
void f (struct interrupt_frame *frame) {
    ...
}
and user must properly define the structure the pointer pointing to.

exception handler: 

The exception handler is very similar to the interrupt handler with a different mandatory function signature:
#ifdef __x86_64__
typedef unsigned long long int uword_t;
#else
typedef unsigned int uword_t;
#endif

struct interrupt_frame;

__attribute__ ((interrupt))
void f (struct interrupt_frame *frame, uword_t error_code) {
    ...
}
and compiler pops the error code off stack before the IRET instruction.

The exception handler should only be used for exceptions which push an error code and all other exceptions must use the interrupt handler.
The system will crash if the wrong handler is used.
Differential Revision: http://reviews.llvm.org/D15709

llvm-svn: 257867
2016-01-15 04:06:31 +00:00
George Burgess IV 60bc972575 [Sema] Suppress diags in overload resolution.
We were emitting diagnostics from our shiny new C-only overload
resolution mode. This patch attempts to silence all such diagnostics.

This fixes PR26085.
Differential Revision: http://reviews.llvm.org/D16159

llvm-svn: 257710
2016-01-13 23:36:34 +00:00
George Burgess IV df1ed0099b [Bugfix] Fix ICE on constexpr vector splat.
In {CG,}ExprConstant.cpp, we weren't treating vector splats properly.
This patch makes us treat splats more properly.

Additionally, this patch adds a new cast kind which allows a bool->int
cast to result in -1 or 0, instead of 1 or 0 (for true and false,
respectively), so we can sanely model OpenCL bool->int casts in the AST.

Differential Revision: http://reviews.llvm.org/D14877

llvm-svn: 257559
2016-01-13 01:52:39 +00:00
Xiuli Pan 9c14e28211 [OpenCL] Pipe type support
Summary:
Support for OpenCL 2.0 pipe type.
This is a bug-fix version for bader's patch reviews.llvm.org/D14441


Reviewers: pekka.jaaskelainen, Anastasia

Subscribers: bader, Anastasia, cfe-commits

Differential Revision: http://reviews.llvm.org/D15603

llvm-svn: 257254
2016-01-09 12:53:17 +00:00
Aaron Ballman 9a17c85454 Properly track that a character literal is UTF-8, and pretty print the prefix properly.
llvm-svn: 257097
2016-01-07 20:59:26 +00:00
George Burgess IV 7204ed97dd [Sema] Teach overload resolution about unaddressable functions.
Given an expression like `(&Foo)();`, we perform overload resolution as
if we are calling `Foo` directly. This causes problems if `Foo` is a
function that can't have its address taken. This patch teaches overload
resolution to ignore functions that can't have their address taken in
such cases.

Differential Revision: http://reviews.llvm.org/D15590

llvm-svn: 257016
2016-01-07 02:26:57 +00:00
John McCall 8a43a0df68 Properly bind up any cleanups in an ExprWithCleanups after
instantiating a default argument expression.

This was previously just working implicitly by reinstantiating
in the current context, but caching means that we weren't
registering cleanups in subsequent uses.

llvm-svn: 256996
2016-01-06 23:34:20 +00:00
John McCall 32791cc3e1 Only instantiate a default argument once.
By storing the instantiated expression back in the ParmVarDecl,
we remove the last need for separately storing the sub-expression
of a CXXDefaultArgExpr.  This makes PCH/Modules merging quite
simple: CXXDefaultArgExpr records are serialized as references
to the ParmVarDecl, and we ignore redundant attempts to overwrite
the instantiated expression.

This has some extremely marginal impact on user-facing semantics.
However, the major effect is that it avoids IRGen errors about
conflicting definitions due to lambdas in the argument being
instantiated multiple times while sharing the same mangling.
It should also slightly improve memory usage and module file size.

rdar://23810407

llvm-svn: 256983
2016-01-06 22:34:54 +00:00
James Y Knight 7281c357b1 [TrailingObjects] Convert OffsetOfExpr.
That necessitated moving the OffsetOfNode class out of OffsetOfExpr.

llvm-svn: 256590
2015-12-29 22:31:18 +00:00
Sanjay Patel 71fca736bc fix typos; NFC
llvm-svn: 256576
2015-12-29 20:09:37 +00:00
Richard Smith de6d6c4860 Teach typo correction to properly handle mapping declarations to their
underlying decls. Preserve the found declaration throughout, and only map to
the underlying declaration when we want to check whether it's the right kind.
This allows us to provide the right source location for the found declaration,
and prepares for the possibility of underlying decls with a different name
from the found decl.

llvm-svn: 256575
2015-12-29 19:43:10 +00:00
Yaron Keren 442dfb4fc0 Replace isa+cast with dyn_cast and obey the no else after return rule.
llvm-svn: 256349
2015-12-23 20:38:13 +00:00
Craig Topper dfe29ae5db [Sema] Use range-based for loops. NFC
llvm-svn: 256135
2015-12-21 06:35:56 +00:00
Richard Smith db0ac5572f Split RequireCompleteType into a function that actually requires that the type
is complete (with an error produced if not) and a function that merely queries
whether the type is complete. Either way we'll trigger instantiation if
necessary, but only the former will diagnose and recover from missing module
imports.

The intent of this change is to prevent a class of bugs where code would call
RequireCompleteType(..., 0) and then ignore the result. With modules, we must
check the return value and use it to determine whether the definition of the
type is visible.

This also fixes a debug info quality issue: calls to isCompleteType do not
trigger the emission of debug information for a type in limited-debug-info
mode. This allows us to avoid emitting debug information for type definitions
in more cases where we believe it is safe to do so.

llvm-svn: 256049
2015-12-18 22:40:25 +00:00
Richard Smith 0f59cb38e7 Wire a SourceLocation into IsDerivedFrom and move the RequireCompleteType call
for the derived class into it. This is mostly just a cleanup, but could in
principle be a bugfix if there is some codepath that reaches here and didn't
previously require a complete type (I couldn't find any such codepath, though).

llvm-svn: 256037
2015-12-18 21:45:41 +00:00
Craig Topper 84543b09cb [Sema] Add -Wparentheses warnings for '^' in '|' expressions and '&' in '^' expressions to compliment '&' in '|' that is already present. Matches gcc behavior.
llvm-svn: 255450
2015-12-13 05:41:41 +00:00
Craig Topper b0dfa7a79a [Sema] Write some checks for groups of BinaryOperatorKinds in terms of the predicates already available in BinaryOperator. NFC
llvm-svn: 255449
2015-12-13 05:41:37 +00:00
Craig Topper 716d3088e1 Minor formatting cleanup. NFC
llvm-svn: 255428
2015-12-12 06:30:51 +00:00
Craig Topper f942fde819 [Sema] Simplify a couple if statements. Explicitly check up front that only one of the expressions is a comparision op. Then if we find that either is a bitwise op, we know it must be the other one. NFC
llvm-svn: 255427
2015-12-12 06:30:48 +00:00
Anastasia Stulova 2446b8ba8a [OpenCL 2.0] In OpenCL v2.0 s6.5 all pointers are implicitly in generic
address space unless address space is explicitly specified.

Correct the behavior of NULL constant detection -
generic AS void pointer should be accepted as a valid NULL constant.

http://reviews.llvm.org/D15293

llvm-svn: 255346
2015-12-11 17:41:19 +00:00
Anastasia Stulova f016a1bb86 Reverting r255337 as it seems to kill bots. Needs investigation.
llvm-svn: 255339
2015-12-11 15:23:00 +00:00
Anastasia Stulova 12e484e80a [OpenCL 2.0] In OpenCL v2.0 s6.5 all pointers are implicitly in generic
address space unless address space is explicitly specified.

Correct the behavior of NULL constant detection -
generic AS void pointer should be accepted as a valid NULL constant.

http://reviews.llvm.org/D15293

llvm-svn: 255337
2015-12-11 13:49:15 +00:00
Craig Topper a92ffb011e [Sema] Use UnaryOperatorKind and BinaryOperatorKind in parameter lists instead of just unsigned. Removes a few explicit casts. NFC
llvm-svn: 255232
2015-12-10 08:51:49 +00:00
Craig Topper bd44cd9d55 [Sema] Remove tab characters. NFC
llvm-svn: 255004
2015-12-08 04:33:04 +00:00
George Burgess IV 3e3bb95b69 Add the `pass_object_size` attribute to clang.
`pass_object_size` is our way of enabling `__builtin_object_size` to
produce high quality results without requiring inlining to happen
everywhere.

A link to the design doc for this attribute is available at the
Differential review link below.

Differential Revision: http://reviews.llvm.org/D13263

llvm-svn: 254554
2015-12-02 21:58:08 +00:00
Samuel Antao 4af1b7b693 [OpenMP] Update target directive codegen to use 4.5 implicit data mappings.
Summary:
This patch implements the 4.5 specification for the implicit data maps. OpenMP 4.5 specification changes the default way data is captured into a target region. All the non-aggregate kinds are passed by value by default. This required activating the capturing by value during SEMA for the target region. All the non-aggregate values that can be encoded in the size of a pointer are properly casted and forwarded to the runtime library. On top of fixing the previous weird behavior for mapping pointers in nested data regions (an explicit map was always required), this also improves performance as the number of allocations/transactions to the device per non-aggregate map are reduced from two to only one - instead of passing a reference and the value, only the value passed.

Explicit maps will be added later on once firstprivate, private, and map clauses' SEMA and parsing are available.

Reviewers: hfinkel, rjmccall, ABataev

Subscribers: cfe-commits, carlo.bertolli

Differential Revision: http://reviews.llvm.org/D14940

llvm-svn: 254521
2015-12-02 17:44:43 +00:00
Richard Smith 4a0cd89325 P0002R1: increment on expressions of type bool is no longer allowed in C++1z.
llvm-svn: 254122
2015-11-26 02:16:37 +00:00
Alexey Bataev f763027f04 [MSVC] 'property' with an empty array in array subscript expression.
MSVC supports 'property' attribute and allows to apply it to the declaration of an empty array in a class or structure definition.
For example:
```
__declspec(property(get=GetX, put=PutX)) int x[];
```
The above statement indicates that x[] can be used with one or more array indices. In this case, i=p->x[a][b] will be turned into i=p->GetX(a, b), and p->x[a][b] = i will be turned into p->PutX(a, b, i);
Differential Revision: http://reviews.llvm.org/D13336

llvm-svn: 254067
2015-11-25 12:01:00 +00:00
Craig Topper da7b27ff0b [Sema] Combine similar diagnostics using %select. NFC
llvm-svn: 253315
2015-11-17 05:40:09 +00:00
Craig Topper 07fa176669 Use Sema::getLocForEndOfToken instead of Preprocessor::getLocForEndOfToken. NFC
llvm-svn: 253155
2015-11-15 02:31:46 +00:00
Richard Smith e301ba2b48 Add support for GCC's '__auto_type' extension, per the GCC manual:
https://gcc.gnu.org/onlinedocs/gcc/Typeof.html

Differences from the GCC extension:
 * __auto_type is also permitted in C++ (but only in places where
   it could appear in C), allowing its use in headers that might
   be shared across C and C++, or used from C++98
 * __auto_type can be combined with a declarator, as with C++ auto
   (for instance, "__auto_type *p")
 * multiple variables can be declared in a single __auto_type
   declaration, with the C++ semantics (the deduced type must be
   the same in each case)

This patch also adds a missing restriction on applying typeof to
a bit-field, which GCC has historically rejected in C (due to
lack of clarity as to whether the operand should be promoted).
The same restriction also applies to __auto_type in C (in both
GCC and Clang).

This also fixes PR25449.

Patch by Nicholas Allegra!

llvm-svn: 252690
2015-11-11 02:02:15 +00:00
Craig Topper 882bc8dfed Use makeArrayRef instead of explicitly mentioning the type. NFC
llvm-svn: 252398
2015-11-07 06:16:16 +00:00
Aaron Ballman b035cd7ea4 The control expression for a _Generic selection expression should have
its type decayed and qualifiers stripped when determining which
selection it matches. Fixes PR16340.

llvm-svn: 252104
2015-11-05 00:06:05 +00:00
Richard Smith 9f690bd80b [coroutines] Creation of promise object, lookup of operator co_await, building
of await_* calls, and AST representation for same.

llvm-svn: 251387
2015-10-27 06:02:45 +00:00
John McCall 460ce58fa6 Define weak and __weak to mean ARC-style weak references, even in MRC.
Previously, __weak was silently accepted and ignored in MRC mode.
That makes this a potentially source-breaking change that we have to
roll out cautiously.  Accordingly, for the time being, actual support
for __weak references in MRC is experimental, and the compiler will
reject attempts to actually form such references.  The intent is to
eventually enable the feature by default in all non-GC modes.
(It is, of course, incompatible with ObjC GC's interpretation of
__weak.)

If you like, you can enable this feature with
  -Xclang -fobjc-weak
but like any -Xclang option, this option may be removed at any point,
e.g. if/when it is eventually enabled by default.

This patch also enables the use of the ARC __unsafe_unretained qualifier
in MRC.  Unlike __weak, this is being enabled immediately.  Since
variables are essentially __unsafe_unretained by default in MRC,
the only practical uses are (1) communication and (2) changing the
default behavior of by-value block capture.

As an implementation matter, this means that the ObjC ownership
qualifiers may appear in any ObjC language mode, and so this patch
removes a number of checks for getLangOpts().ObjCAutoRefCount
that were guarding the processing of these qualifiers.  I don't
expect this to be a significant drain on performance; it may even
be faster to just check for these qualifiers directly on a type
(since it's probably in a register anyway) than to do N dependent
loads to grab the LangOptions.

rdar://9674298

llvm-svn: 251041
2015-10-22 18:38:17 +00:00
Craig Topper b5518246b2 Use an ArrayRef<OffsetOfComponent> instead of pointer and size throughout offsetof handling code. Also use a range-based for loop. NFC
llvm-svn: 250989
2015-10-22 04:59:59 +00:00
Craig Topper d8040cfa9f Use front() instead of [0] to make code more consistent with the next line that uses back().
llvm-svn: 250970
2015-10-22 01:56:16 +00:00
George Burgess IV 5f21c71800 [Sema] Make `&function_with_enable_if_attrs` an error
This fixes a bug where one can take the address of a conditionally
enabled function to drop its enable_if guards. For example:

  int foo(int a) __attribute__((enable_if(a > 0, "")));
  int (*p)(int) = &foo;
  int result = p(-1); // compilation succeeds; calls foo(-1)

Overloading logic has been updated to reflect this change, as well.

Functions with enable_if attributes that are always true are still
allowed to have their address taken.

Differential Revision: http://reviews.llvm.org/D13607

llvm-svn: 250090
2015-10-12 19:57:04 +00:00
George Burgess IV 4546181e12 [Sema] Allow C conversions in C overload logic
C allows for some implicit conversions that C++ does not, e.g. void* ->
char*. This patch teaches clang that these conversions are okay when
dealing with overloads in C.

Differential Revision: http://reviews.llvm.org/D13604

llvm-svn: 249995
2015-10-11 20:13:20 +00:00
Vedant Kumar 55c214484c [Sema] Add "Ty" suffix to QualType variables for clarity (NFC)
llvm-svn: 249801
2015-10-09 01:47:26 +00:00
Richard Smith 42fd9efa38 Revert r107690 (for PR7417) and add a testcase that it breaks. The approach of
that change turns out to not be reasonable: mutating the AST of a parsed
template during instantiation is not a sound thing to do, does not work across
chained PCH / modules builds, and is in any case a special-case workaround to a
more general problem that should be solved centrally.

llvm-svn: 249342
2015-10-05 20:05:21 +00:00
Craig Topper e335f25949 SourceRanges are small and trivially copyable, don't them by reference.
llvm-svn: 249259
2015-10-04 04:53:55 +00:00
Samuel Antao 4be30e92dc [OpenMP] Capture global variables in target regions.
All global variables that are not enclosed in a declare target region 
must be captured in the target region as local variables do. Currently, 
there is no support for declare target, so this patch adds support for 
capturing all the global variables used in a the target region.

llvm-svn: 249154
2015-10-02 17:14:03 +00:00
Reid Kleckner 21525e7fd4 [Sema] Avoid crashing during this-> insertion recovery
We get into this bad state when someone defines a new member function
for a class but forgets to add the declaration to the class body.
Calling the new member function from a member function template of the
class will crash during instantiation.

llvm-svn: 248925
2015-09-30 17:30:48 +00:00
Anastasia Stulova e6e082348d [OpenCL] Add missing OpenCL LangOpts in address space compatibility checks
and test checking broken (due to CL specific diagnostics) C functionality

M    test/Sema/address_spaces.c
M    lib/Sema/SemaExpr.cpp

llvm-svn: 248902
2015-09-30 13:49:55 +00:00
Anastasia Stulova de0e424e8a [OpenCL 2.0] This change adds extra diagnostics to atomic types
Applied restrictions from OpenCL v2.0 s6.13.11.8
that mainly disallow operations on atomic types (except for taking their address - &).

The patch is taken from SPIR2.0 provisional branch, contributed by Guy Benyei!

llvm-svn: 248896
2015-09-30 13:18:52 +00:00
Alexey Bataev a176421da5 [OPENMP 4.1] Sema analysis for array sections in 'reduction' clause.
OpenMP 4.1 allows to use array sections|subscript expressions in 'reduction' clauses. Added sema analysis, updated tests.

llvm-svn: 248880
2015-09-30 09:22:36 +00:00
Charles Davis c7d5c94f78 Support __builtin_ms_va_list.
Summary:
This change adds support for `__builtin_ms_va_list`, a GCC extension for
variadic `ms_abi` functions. The existing `__builtin_va_list` support is
inadequate for this because `va_list` is defined differently in the Win64
ABI vs. the System V/AMD64 ABI.

Depends on D1622.

Reviewers: rsmith, rnk, rjmccall

CC: cfe-commits

Differential Revision: http://reviews.llvm.org/D1623

llvm-svn: 247941
2015-09-17 20:55:33 +00:00
Stephen Canon ca8eefddb7 Prevent implicit re-interpret casts between ExtVector and Scalar types.
Previously, in certain cases lax vector conversions could occur between scalar floating-point values and ExtVector types; these conversions would be simple bitcasts.  We need to allow them with other vector types to support some common headers, but we don't need them for ExtVector.  Preventing them here makes them behave like other operations involving scalars and ExtVectors.

llvm-svn: 247643
2015-09-15 00:21:56 +00:00
David Majnemer cca07d7c48 [MS ABI] Select a pointer to member representation more often
Given a reference to a pointer to member whose class's inheritance model
is unspecified, make sure we come up with an inheritance model in
plausible places.  One place we were missing involved LValue to RValue
conversion, another involved unary type traits.

llvm-svn: 247248
2015-09-10 07:20:05 +00:00
Alexey Bataev b500101e1c [OPENMP] Fix for http://llvm.org/PR24687: ICE on compilation of R package TPmsm.
Fixed capturing of VLAs in 'private' clause of the OpenMP directives.

llvm-svn: 246757
2015-09-03 10:21:46 +00:00
Aaron Ballman 6924dcdf6f Add a new frontend warning for referencing members from the handler of a constructor or destructor function-try-block, which is UB in C++.
This corresponds to the CERT secure coding rule ERR53-CPP.

llvm-svn: 246548
2015-09-01 14:49:24 +00:00
Alexey Bader f961e755b1 [OpenCL] Improve diagnostics detecting implicit vector conversion.
Reviewers: pekka.jaaskelainen

Differential Revision: http://reviews.llvm.org/D12470

llvm-svn: 246393
2015-08-30 18:06:39 +00:00
David Majnemer d39bcaed21 [Sema] Don't assume CallExpr::getDirectCallee will succeed
We tried to provide a very nice diagnostic when diagnosing an assignment
to a const int & produced by a function call.  However, we cannot always
determine what function was called.

This fixes PR24568.

llvm-svn: 246014
2015-08-26 05:13:19 +00:00
Alexey Bataev 627cbd31d1 Fix possible crash on null base or type for array elements.
llvm-svn: 245939
2015-08-25 15:15:12 +00:00
Alexey Bataev 1a3320e463 [OPENMP 4.0] Initial support for array sections.
Adds parsing/sema analysis/serialization/deserialization for array sections in OpenMP constructs (introduced in OpenMP 4.0).
Currently it is allowed to use array sections only in OpenMP clauses that accepts list of expressions.
Differential Revision: http://reviews.llvm.org/D10732

llvm-svn: 245937
2015-08-25 14:24:04 +00:00
Olivier Goffart 66be61ad4f Fix crash with two typos in the arguments of a function
The problem is that the arguments are of TheCall are reset later
to the ones in Args, making TypoExpr put back. Some TypoExpr that have
already  been diagnosed and will assert later in Sema::getTypoExprState

llvm-svn: 245560
2015-08-20 13:11:14 +00:00
Richard Trieu 1cd076eb34 Fix -Wlogical-not-parentheses to work better with C code.
Remove the assumption of a Boolean type by checking if an expression is known
to have a boolean value.  Disable warning in two other tests.

llvm-svn: 245507
2015-08-19 21:33:54 +00:00