Commit Graph

13650 Commits

Author SHA1 Message Date
Saleem Abdulrasool 765a219431 Sema: correct typo correction for ivars in @implementation
The previous typo correction handling assumed that ivars are only declared in
the interface declaration rather than as a private ivar in the implementation.
Adjust the handling to permit both interfaces.  Assert earlier that the
interface has been acquired to ensure that we can identify when both possible
casts have failed.

Addresses PR31040!

llvm-svn: 287238
2016-11-17 17:10:54 +00:00
George Burgess IV 004319554c [Sema] Fix a bug in enable_if condition instantiation.
During template instantiation, we currently fall back to just calling
Sema::SubstExpr for enable_if attributes that aren't value-dependent or
type-dependent. Since Sema::SubstExpr strips off any implicit casts
we've added to an expression, it's possible that this behavior will
leave us with an enable_if condition that's just a DeclRefExpr.
Conditions like that deeply confuse Sema::CheckEnableIf.

llvm-svn: 287187
2016-11-17 01:33:54 +00:00
Reid Kleckner ad425626d2 Add warning when assigning enums to bitfields without an explicit unsigned underlying type
Summary:
Add a warning when assigning enums to bitfields without an explicit
unsigned underlying type. This is to prevent problems with MSVC
compatibility, since the Microsoft ABI defaults to storing enums with a
signed type, causing inconsistencies with saving to/reading from
bitfields.

Also disabled the warning in the dr0xx.cpp test which throws the error,
and added a test for the warning.

The warning can be disabled with -Wno-signed-enum-bitfield.

Patch by Sasha Bermeister!

Reviewers: rnk, aaron.ballman

Subscribers: mehdi_amini, aaron.ballman, cfe-commits, thakis, dcheng

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

llvm-svn: 287177
2016-11-16 23:40:00 +00:00
George Burgess IV add6ab5084 Use the member function location in enable_if diagnostics.
Before:
<stdin>:3:3: error: no matching member function for call to 'bar'
  Foo().bar();
  ^

After:
<stdin>:3:9: error: no matching member function for call to 'bar'
  Foo().bar();
        ^

llvm-svn: 287154
2016-11-16 21:31:25 +00:00
Benjamin Kramer 7de9969bb0 [Frontend] Allow attaching an external sema source to compiler instance and extra diags to TypoCorrections
This can be used to append alternative typo corrections to an existing diag.
include-fixer can use it to suggest includes to be added.

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

llvm-svn: 287128
2016-11-16 18:15:26 +00:00
Yaron Keren 1cb8146057 Rangify for loop, NFC.
llvm-svn: 287102
2016-11-16 13:45:34 +00:00
Joey Gouly f9889f22a9 [OpenCL] Use the semantic spelling of the Access attribute, rather than a string.
Also fix a latent bug, due to an incorrect traversal of the AttributeList.

llvm-svn: 287100
2016-11-16 11:34:09 +00:00
Simon Pilgrim b17efcbcc5 Fixed spelling in comments. NFCI.
llvm-svn: 286996
2016-11-15 18:28:07 +00:00
Alexey Bataev f7300d5cb1 [OPENMP] Fix for PR30632: Name mangling issue.
Reworked fix after comments from Richard Smith. We must skip all
CapturedDecl-based contexts when trying to get correct mangling number
context.

llvm-svn: 286953
2016-11-15 13:15:20 +00:00
Anastasia Stulova 0df4ac3f94 [OpenCL] Fix for integer parameters of enqueue_kernel
Make handling integer parameters more flexible:

- For the number of events argument allow to pass larger
integers than 32 bits as soon as compiler can prove that
the range fits in 32 bits. If not, the diagnostic will be given.

- Change type of the arguments specifying the sizes of
the corresponding block arguments to be size_t.

Review: https://reviews.llvm.org/D26509
llvm-svn: 286849
2016-11-14 17:39:58 +00:00
Anastasia Stulova 2b46120a09 [OpenCL] Change to clk_event parameter in enqueue_kernel.
- Accept NULL pointer as a valid parameter value for clk_event.
- Generate clk_event_t arguments of internal
__enqueue_kernel_XXX function as pointers in generic address space.

Review: https://reviews.llvm.org/D26507
llvm-svn: 286836
2016-11-14 15:34:01 +00:00
Renato Golin 6a051ba614 Revert "Improve handling of floating point literals in OpenCL to only use double precision if the target supports fp64."
This reverts commit r286815, as it broke all ARM and AArch64 bots.

llvm-svn: 286818
2016-11-14 12:19:18 +00:00
Neil Hickey f603672b5c Improve handling of floating point literals in OpenCL to only use double precision if the target supports fp64.
This change makes sure single-precision floating point types are used if the 
cl_fp64 extension is not supported by the target.

Also removed the check to see whether the OpenCL version is >= 1.2, as this has
been incorporated into the extension setting code.

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

llvm-svn: 286815
2016-11-14 11:15:51 +00:00
Roger Ferrer Ibanez e3d8026cc7 Remove some false positives when taking the address of packed members
Differential Revision: https://reviews.llvm.org/D23657

llvm-svn: 286798
2016-11-14 08:53:27 +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
Serge Pavlov 3852637005 Use descriptive message if list initializer is incorrectly parenthesized.
If initializer contains parentheses around braced list where it is not allowed,
as in construct int({0}), clang issued message like `functional-style cast
from 'void' to 'int' is not allowed`, which does not help much. Both gcc and
msvc issue message `list-initializer for non-class type must not be
parenthesized`, which is more descriptive. This change implements similar
message for clang.

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

llvm-svn: 286721
2016-11-12 15:38:55 +00:00
Craig Topper 1a44193afd [AVX-512] Convert the rest of the masked shift by immediate and by single element builtins over to the newly added unmasked builtins and a select.
This should also fix PR30691 since the new builtins are handled like the legacy builtins in the backend.

llvm-svn: 286714
2016-11-12 07:16:59 +00:00
Richard Trieu 59e635a5cb Remove double setting of invalid flag.
In r286630, Decl::setInvalidDecl will automatically set the invalid flag for
BindingDecl for children in invalid DecompositionDecl.  It no longer is
necessary to do a separate setInvalidDecl when finalizing a BindingDecl.

llvm-svn: 286641
2016-11-11 21:50:39 +00:00
Alexey Bataev 31939e39db Fix for PR28523: unexpected compilation error.
Clang emits error message for the following code:
```
template <class F> void parallel_loop(F &&f) { f(0); }

int main() {
  int x;
  parallel_loop([&](auto y) {
    {
      x = y;
    };
  });
}
```

$ clang++ --std=gnu++14 clang_test.cc -o clang_test
clang_test.cc:9:7: error: reference to local variable 'x' declared in enclosing function 'main'
      x = y;
            ^
clang_test.cc:2:48: note: in instantiation of function template specialization 'main()::(anonymous class)::operator()<int>' requested here
            template <class F> void parallel_loop(F &&f) { f(0); }
                                                           ^
clang_test.cc:6:3: note: in instantiation of function template specialization 'parallel_loop<(lambda at clang_test.cc:6:17)>' requested here parallel_loop([&](auto y) {
           ^
clang_test.cc:5:7: note: 'x' declared here
      int x;
          ^
1 error generated.

Patch fixes this issue.

llvm-svn: 286584
2016-11-11 12:36:20 +00:00
Jordan Rose bd1ee4830d Don't require nullability on 'va_list', even when it's a pointer.
Take 3! This should finally fix the Hexagon, PPC, and Windows bots.

rdar://problem/25846421

llvm-svn: 286542
2016-11-11 01:29:18 +00:00
Jordan Rose 9f10af2aa2 Revert "Speculative fix for va_list/nullability test on Hexagon and PPC."
This reverts commit r286533. At this point an array really is still an
array, but the problem is with /non-/array va_lists anyway.

llvm-svn: 286541
2016-11-11 01:29:15 +00:00
Jordan Rose b07c0d7085 Speculative fix for va_list/nullability test on Hexagon and PPC.
PowerPC's va_list, at least, is a typedef for an array, which means it
decays to a pointer in parameter position. Since the decayed type is
built from the array element type, the typedef sugar is lost.

More rdar://problem/25846421.

llvm-svn: 286533
2016-11-11 00:55:14 +00:00
Jordan Rose 0f94d97cba Don't require nullability on 'va_list' harder.
Platform headers don't always define 'va_list' in terms of Clang's
'__builtin_va_list', so in addition to checking for our own
synthesized decl, also just look for typedefs literally named
'va_list'. Better to err on the side of false negatives here.

Fix-up for rdar://problem/25846421.

llvm-svn: 286531
2016-11-11 00:23:59 +00:00
Jordan Rose ff82547f98 [Sema] Fix-up for MSVC, which is stricter about template types.
llvm-svn: 286525
2016-11-10 23:41:18 +00:00
Jordan Rose 16d52a2a72 Don't require nullability on 'va_list'.
There are many non-portable typedefs, but va_list is one that nobody
ever thinks of as a pointer or an array. (When's the last time you saw
someone check for a NULL va_list?) Make an exception for this one
special type.

Part of rdar://problem/25846421.

llvm-svn: 286522
2016-11-10 23:28:34 +00:00
Jordan Rose 3b917fe019 Warn when 'assume_nonnull' infers nullability within an array.
...or within a reference. Both of these add an extra level of
indirection that make us less certain that the pointer really was
supposed to be non-nullable. However, changing the default behavior
would be a breaking change, so we'll just make it a warning instead.

Part of rdar://problem/25846421

llvm-svn: 286521
2016-11-10 23:28:30 +00:00
Jordan Rose f85a9b06b8 Add -Wnullability-completeness-on-arrays.
This is an addition to (and sub-warning of) -Wnullability-completeness
that warns when an array parameter is missing nullability. When the
specific warning is switched off, the compiler falls back to only
warning on pointer types written as pointer types.

Note that use of nullability /within/ an array triggers the
completeness checks regardless of whether or not the array-specific
warning is enabled; the intent there is simply to determine whether a
particular header is trying to be nullability-aware at all.

Part of rdar://problem/25846421.

llvm-svn: 286520
2016-11-10 23:28:26 +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
George Burgess IV 0d546534d3 [Sema] Range-ify for loop, add period to comment. NFC.
llvm-svn: 286506
2016-11-10 21:47:12 +00:00
Alex Lorenz d60bb28307 [Sema] Avoid -Wshadow warnings for shadowed variables that
aren't captured by lambdas with a default capture specifier

This commit is a follow-up to r286354. It avoids the -Wshadow warning for
variables which shadow variables that aren't captured by lambdas with a default
capture specifier. It provides an additional note that points to location of
the capture.

The old behaviour is preserved with -Wshadow-all or -Wshadow-uncaptured-local.

rdar://14984176

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

llvm-svn: 286465
2016-11-10 16:19:11 +00:00
Shoaib Meenai ab3f96cb21 [Sema] Use MS ABI behavior for dllexport in Itanium
Similar to r284288, make the Itanium ABI follow MS ABI dllexport
semantics in the case of an explicit instantiation declaration followed
by a dllexport explicit instantiation definition.

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

llvm-svn: 286419
2016-11-09 23:52:20 +00:00
Erik Pilkington 5dbe7a9362 [Sema][NFC] Reset HasFallthroughStmt when clearing FunctionScopeInfo
Differential revision: https://reviews.llvm.org/D22770

llvm-svn: 286409
2016-11-09 22:52:23 +00:00
Alex Lorenz baef802f36 [CodeCompletion] Show block invocation results for block property setters
This commit changes the code completion results for block property setters:
The default block property result is now a block invocation rather than a simple
property reference.

rdar://28846196

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

llvm-svn: 286363
2016-11-09 13:43:18 +00:00
Alex Lorenz 175388c00d [Sema] Avoid -Wshadow warnings for shadowed variables that aren't captured
by lambdas with an explicit capture list

This commit avoids the -Wshadow warning for variables which shadow variables
that aren't captured by lambdas with an explicit capture list. It provides an
additional note that points to location of the explicit capture.

The old behaviour is preserved with -Wshadow-all or -Wshadow-uncaptured-local.

rdar://17135966

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

llvm-svn: 286354
2016-11-09 10:38:57 +00:00
Argyrios Kyrtzidis f95a000421 [index] Fix issue with protocol name locations in conformance list of an ObjC class when they come from a typedef.
The ObjC class protocol list assumes there is an associated location for each protocol but no location is provided
when the protocol list comes from a typedef, and we end up with a buffer overflow when trying to get locations for the protocol names.

Fixes crash of rdar://28980278.

llvm-svn: 286331
2016-11-09 02:47:07 +00:00
Justin Lebar 2d56c26504 [CUDA] Use only the GVALinkage on function definitions.
Summary:
Previously we'd look at the GVALinkage of whatever FunctionDecl you
happened to be calling.

This is not right.  In the absence of the gnu_inline attribute, to be
handled separately, the function definition determines the function's
linkage.  So we need to wait until we get a def before we can know
whether something is known-emitted.

Reviewers: tra

Subscribers: cfe-commits, rsmith

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

llvm-svn: 286313
2016-11-08 23:45:51 +00:00
Vladimir Yakovlev 9e83e22ddf Test commit of vbyakovl.
llvm-svn: 286224
2016-11-08 10:32:10 +00:00
Richard Smith 5e05298549 Correctly ignore unnamed bit-fields when checking whether a union has fields.
llvm-svn: 286189
2016-11-08 01:07:26 +00:00
Craig Topper 8e06631b09 [AVX-512][Sema] Add more intrinsics to the checks for valid immediates for embedded rounding control arguments.
llvm-svn: 286097
2016-11-07 07:01:09 +00:00
Olivier Goffart d211c648b9 [index] Expose FriendDecl
Differential Revision: https://reviews.llvm.org/D26285

llvm-svn: 285984
2016-11-04 06:29:27 +00:00
Chandler Carruth 6232e4d5d9 Delete a trivially true check for a variable 'S' being null.
The exact same test guards entry into the loop in which this test
occurs, and there is nothing inside the loop that assigns to the
variable, so it has already been checked for null.

This was flagged by PVS-Studio as well, but the report is actually wrong
-- this is not a case where we dereference a variable prior to testing
it for null, this is a case where we have a redundant test for null
after we already performed the exact same test.

llvm-svn: 285983
2016-11-04 06:16:09 +00:00
Chandler Carruth 3d40284570 Add an assert to further check the invariant that a null pointer
corresponds to another argument being valid.

This makes it clear that the code is correct despite the PVS-Studio
report that a pointer might be dereferenced prior to being checked for
whether it is null. It likely is also enough for static analyzers to not
flag the code.

llvm-svn: 285982
2016-11-04 06:11:54 +00:00
Chandler Carruth ede11636a5 Remove no-op checks for a null CodeCompleter. We have already
dereferenced the pointer at this point, and these routines are
exclusively called after the parser encounters a code completion token.
Other code completion routines called at that point do not check for
null either, so this is clearly the current invariant expected in the
code.

This fixes another PVS-Studio found issue.

llvm-svn: 285980
2016-11-04 06:06:50 +00:00
Akira Hatanaka 40c15abe5f Fix spelling mistake.
llvm-svn: 285938
2016-11-03 17:11:28 +00:00
Akira Hatanaka 43556c14fe [Sema] Avoid instantiating templates only when UncompilableErrorOccurred
and FatalErrorOccurred are both set.

This fixes a crash that occurs when a warning promoted to a fatal error
leaves the AST in an incomplete state, and then later CFG analysis is
run on the incomplete AST.

rdar://problem/28558923

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

llvm-svn: 285923
2016-11-03 15:04:58 +00:00
Vedant Kumar e03e5953f6 [Sema] Remove a dead assignment, NFC.
The assignment to NextIsDereference is either followed by (1) another,
unrelated assignment to NextIsDereference or by (2) an early loop exit.

Found by clang's static analyzer: http://llvm.org/reports/scan-build

(While we're at it fix a typo.)

llvm-svn: 285879
2016-11-03 06:35:16 +00:00
Eric Fiselier e4e9e281a1 [Sema] Allow static_cast<T&&>(e) to check explicit conversions for non-reference-related types.
Summary:
[expr.cast.static] states:
> 3. A glvalue of type “cv1 T1” can be cast to type “rvalue reference to cv2 T2” if “cv2 T2” is reference-compatible
> with “cv1 T1”. The result refers to the object or the specified base class subobject thereof. If T2 is
> an inaccessible or ambiguous base class of T1, a program that necessitates such a cast is
> ill-formed.
> 
> 4. Otherwise, an expression e can be explicitly converted to a type T using a static_cast of the form static_-
> cast<T>(e) if the declaration T t(e); is well-formed, for some invented temporary variable t. [...]

Currently when checking p3 Clang will diagnose `static_cast<T&&>(e)` as invalid if the argument is not reference compatible with `T`. However I believe the correct behavior is to also check p4 in those cases.  For example:

```
double y = 42;
static_cast<int&&>(y); // this should be OK.  'int&& t(y)' is well formed
```

Note that we still don't check p4 for non-reference-compatible types which are reference-related since  `T&& t(e);` should never be well formed in those cases.


Reviewers: rsmith

Subscribers: cfe-commits

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

llvm-svn: 285872
2016-11-03 02:13:17 +00:00
Jordan Rose ce65364afc Don't require nullability on template parameters in typedefs.
Previously the following code would warn on the use of "T":

  template <typename T>
  struct X {
    typedef T *type;
  };

...because nullability is /allowed/ on template parameters (because
they could be pointers). (Actually putting nullability on this use of
'T' will of course break if the argument is a non-pointer type.)

This fix doesn't handle the case where a template parameter is used
/outside/ of a typedef. That seems trickier, especially in parameter
position.

llvm-svn: 285856
2016-11-02 20:44:07 +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