Commit Graph

4010 Commits

Author SHA1 Message Date
Nico Weber 8be5d034e4 fix typo "varaible"
llvm-svn: 279639
2016-08-24 16:37:21 +00:00
Vassil Vassilev 8643639ab4 PR28423: Compare primary declaration contexts.
In certain cases (mostly coming from modules), Sema's idea of the StdNamespace
does not point to the first declaration of namespace std.

Patch by Cristina Cristescu!

Reviewed by Richard Smith.

llvm-svn: 279371
2016-08-20 14:50:22 +00:00
Roger Ferrer Ibanez f7b9f3149b Add missing tests
Change r278483 was missing the tests

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

llvm-svn: 278908
2016-08-17 06:52:15 +00:00
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
Richard Smith da38363784 P0217R3: code generation support for decomposition declarations.
llvm-svn: 278642
2016-08-15 01:33:41 +00:00
George Burgess IV 53b938da5a [Sema] Fix a crash on variadic enable_if functions.
Currently, when trying to evaluate an enable_if condition, we try to
evaluate all arguments a user passes to a function. Given that we can't
use variadic arguments from said condition anyway, not converting them
is a reasonable thing to do. So, this patch makes us ignore any varargs
when attempting to check an enable_if condition.

We'd crash because, in order to convert an argument, we need its
ParmVarDecl. Variadic arguments don't have ParmVarDecls.

llvm-svn: 278471
2016-08-12 04:12:31 +00:00
Richard Smith 7b76d81bdf P0217R3: serialization/deserialization support for c++17 decomposition declarations.
llvm-svn: 278460
2016-08-12 02:21:25 +00:00
Richard Smith 3997b1b427 P0217R3: template instantiation support for decomposition declarations.
llvm-svn: 278458
2016-08-12 01:55:21 +00:00
Richard Smith dca60b4958 P0217R3: Constant expression evaluation for decomposition declarations.
llvm-svn: 278447
2016-08-12 00:39:32 +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
Bruno Cardoso Lopes 7ea9fd233b Reapply [Sema] Add sizeof diagnostics for bzero
Reapply r277787. For memset (and others) we can get diagnostics like:

  struct stat { int x; };
  void foo(struct stat *stamps) {
    bzero(stamps, sizeof(stamps));
    memset(stamps, 0, sizeof(stamps));
  }

  t.c:7:28: warning: 'memset' call operates on objects of type 'struct stat' while the size is based on a different type 'struct stat *' [-Wsizeof-pointer-memaccess]
    memset(stamps, 0, sizeof(stamps));
           ~~~~~~            ^~~~~~
  t.c:7:28: note: did you mean to dereference the argument to 'sizeof' (and multiply it by the number of elements)?
    memset(stamps, 0, sizeof(stamps));
                             ^~~~~~

This patch implements the same class of warnings for bzero.

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

rdar://problem/18963514

llvm-svn: 278264
2016-08-10 18:34:47 +00:00
Richard Trieu e056aee9d9 Fix typos from r277797 and unused variable from r277889.
llvm-svn: 277900
2016-08-06 01:44:06 +00:00
Richard Trieu 81b6c561ea Fix two false positives in -Wreturn-stack-address
If the return type is a pointer and the function returns the reference to a
pointer, don't warn since only the value is returned, not the reference.

If a reference function parameter appears in the reference chain, don't warn
since binding happens at the caller scope, so addresses returned are not
to local stack.  This includes default arguments as well.

llvm-svn: 277889
2016-08-05 23:24:47 +00:00
Richard Trieu 71d74d4b25 Fix false positive in -Wunsequenced and templates.
For builtin logical operators, there is a well-defined ordering of argument
evaluation.  For overloaded operator of the same type, there is no argument
evaluation order, similar to other function calls.  When both are present,
uninstantiated templates with an operator&& is treated as an unresolved
function call.  Unresolved function calls are treated as normal function calls,
and may result in false positives when the builtin logical operator is used.
Have the unsequenced checker ignore dependent expressions to avoid this
false positive.  The check also happens in template instantiations to catch
when the overloaded operator is used.

llvm-svn: 277866
2016-08-05 21:02:34 +00:00
Bruno Cardoso Lopes 9e4374daa3 Revert "[Sema] Add sizeof diagnostics for bzero"
This reverts commit r277787, which caused PR28870.

llvm-svn: 277830
2016-08-05 16:41:00 +00:00
Bruno Cardoso Lopes edf3d81cbf [Sema] Add sizeof diagnostics for bzero
For memset (and others) we can get diagnostics like:

  struct stat { int x; };
  void foo(struct stat *stamps) {
    bzero(stamps, sizeof(stamps));
    memset(stamps, 0, sizeof(stamps));
  }

  t.c:7:28: warning: 'memset' call operates on objects of type 'struct stat' while the size is based on a different type 'struct stat *' [-Wsizeof-pointer-memaccess]
    memset(stamps, 0, sizeof(stamps));
           ~~~~~~            ^~~~~~
  t.c:7:28: note: did you mean to dereference the argument to 'sizeof' (and multiply it by the number of elements)?
    memset(stamps, 0, sizeof(stamps));
                             ^~~~~~

This patch implements the same class of warnings for bzero.

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

rdar://problem/18963514

llvm-svn: 277787
2016-08-04 23:55:22 +00:00
Devin Coughlin 6eb1ca7416 [CFG] Fix crash finding destructor of lifetime-extended temporary.
Fix a crash under -Wthread-safety when finding the destructor for a
lifetime-extending reference.

A patch by Nandor Licker!

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

llvm-svn: 277522
2016-08-02 21:07:23 +00:00
Faisal Vali 5e5501861a [NFC] Rearrange an example-file so the c++14 specific example is on top.
This makes it easier to add C++1z examples to the bottom, just before the #endif.

llvm-svn: 277287
2016-07-31 01:19:17 +00:00
Erik Pilkington 3cdc317342 [Sema] Teach getCurrentThisType to reconize lambda in in-class initializer
Fixes PR27994, a crash on valid.

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

llvm-svn: 276900
2016-07-27 18:25:10 +00:00
Faisal Vali c6b9be29f2 [cxx1z-constexpr-lambda] Make a lambda's closure type eligible as a literal-type in C++1z
Additionally, for pre-C++1z, instead of forbidding a lambda's closure type from being a literal type through circumlocutorily setting HasNonLiteralTypeFieldsOrBases falsely to true -- handle lambda's more directly in CXXRecordDecl::isLiteral().

One additional small step towards implementing constexpr-lambdas.

Thanks to Richard Smith for his review! 
https://reviews.llvm.org/D22662

llvm-svn: 276514
2016-07-23 04:05: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
George Burgess IV 92b43a462e [Sema] Fix PR28623.
In atomic builtins, we assumed that the LValue conversion on the first
argument would succeed. So, we would crash given code like:

```
void ovl(char);
void ovl(int);
__atomic_store_n(ovl, 0, 0);
```

This patch makes us not assume that said conversion is successful. :)

llvm-svn: 276232
2016-07-21 03:28:13 +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
Dmitry Polukhin ba57f02720 Deprecated (legacy) string literal conversion to 'char *' causes strange overloading resolution
It's a patch for PR28050. Seems like overloading resolution wipes out
the first standard conversion sequence (before user-defined conversion)
in case of deprecated string literal conversion.

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

Patch by Alexander Makarov

llvm-svn: 275970
2016-07-19 11:29:16 +00:00
Richard Smith 3cbf3f1f59 Push alias-declarations and alias-template declarations into scope even if
they're redeclarations. This is necessary in order for name lookup to correctly
find the most recent declaration of the name (which affects default template
argument lookup and cross-module merging, among other things).

llvm-svn: 275612
2016-07-15 20:53:25 +00:00
Saleem Abdulrasool 511f2e5a89 Sema: support __declspec(dll*) on ObjC interfaces
Extend the __declspec(dll*) attribute to cover ObjC interfaces.  This was
requested by Microsoft for their ObjC support.  Cover both import and export.
This only adds the semantic analysis portion of the support, code-generation
still remains outstanding.  Add some basic initial documentation on the
attributes that were previously empty.  Tweak the previous tests to use the
relative expected-warnings to make the tests easier to read.

llvm-svn: 275610
2016-07-15 20:41:10 +00:00
Paul Robinson 4e0ff9c46b C does not have inline variables.
Add a few missing tests for related C++ diagnostics.

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

llvm-svn: 275493
2016-07-14 22:22:58 +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
Richard Smith a547eb27fa P0305R0: Semantic analysis and code generation for C++17 init-statement for 'if' and 'switch':
if (stmt; condition) { ... }

Patch by Anton Bikineev! Some minor formatting and comment tweets by me.

llvm-svn: 275350
2016-07-14 00:11:03 +00:00
David Majnemer c2406d46b8 [Sema] Don't artificially forbid BuiltinTemplateDecls in CheckTemplateArgument
After thinking about it, we don't really need to forbid
BuiltinTemplateDecls explicitly.  The restriction doesn't really buy us
anything.

llvm-svn: 275078
2016-07-11 17:09:56 +00:00
David Majnemer f580dd98cb [Sema] Disallow __make_integer_seq from showing up in __make_integer_seq
We hit over stringent asserts when trying to diagnose.  Loosen them as
appropriate.

This fixes PR28494.

llvm-svn: 275047
2016-07-11 05:59:24 +00:00
Vassil Vassilev 1002373946 Teach -ast-print to print constexpr variables.
Patch reviewed by Richard Smith (D22168).

llvm-svn: 274930
2016-07-08 21:09:08 +00:00
Vassil Vassilev cdaa31fe84 Don't crash when printing auto variables.
Patch by Axel Naumann!

llvm-svn: 274859
2016-07-08 16:04:22 +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
Eric Fiselier 6ad68551c3 [Feature] Add a builtin for indexing into parameter packs. Patch by Louis Dionne.
This patch adds a __nth_element builtin that allows fetching the n-th type of a
parameter pack with very little compile-time overhead. The patch was inspired by
r252036 and r252115 by David Majnemer, which add a similar __make_integer_seq
builtin for efficiently creating a std::integer_sequence.

Reviewed as D15421. http://reviews.llvm.org/D15421

llvm-svn: 274316
2016-07-01 01:24:09 +00:00
Erik Pilkington fc235eb780 [Sema] Implement C++14's DR1579: Prefer returning by converting move constructor
Fixes PR28096.

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

llvm-svn: 274291
2016-06-30 23:09:13 +00:00
Richard Smith b8c414ccd1 Fix typo-correction crash if a typo occurs within the operand of a
function-style cast to a non-dependent type which is then used in an invalid
way. We'd lose the "type dependent" bit here, and downstream Sema processing
would then discard the expression if it was used in a context where its type
rendered it invalid.

llvm-svn: 274267
2016-06-30 20:24:30 +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
Dmitry Polukhin 90bb49e362 [GCC] PR23529 Mangler part of attrbute abi_tag support
Original patch by Stefan Bühler http://reviews.llvm.org/D12834

Difference between original and this one:
- fixed all failing tests
- fixed mangling for global variable outside namespace
- emit ABI tags for guards and local names
- clang-format + other stylistic changes
- significantly reworked patch according to Richard's suggestions

Sema part, committed before http://reviews.llvm.org/D17567

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

llvm-svn: 274222
2016-06-30 09:40:38 +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 3ffc45f5fd Function declarations are, in fact, permitted in the init-statement of a for
loop. Don't confuse Sema by saying they're not.

llvm-svn: 274080
2016-06-28 23:26:18 +00:00
Manman Ren ccf25bbf3f AvailabilityAttr: we accept "macos" as the platform name.
We continue accepting "macosx" but canonicalize it to "macos", When emitting
diagnostics, we use "macOS" instead of "OS X".

The PlatformName in TargetInfo is changed from "macosx" to "macos" so we can
directly compare the Platform in AvailabilityAttr with the PlatformName
in TargetInfo.

rdar://26795172
rdar://26800775

llvm-svn: 274064
2016-06-28 20:55:30 +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
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 ae72fa2f97 Add a test case for the regression in -Wfor-loop-analysis caused by r273548.
llvm-svn: 273590
2016-06-23 18:11:19 +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
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
Olivier Goffart 12b2219841 Functions declared in a scope should not hide previous declaration in earlier scopes
This code should be an error:

 void foo(int);
 void f3() {
   int foo(float);
   {
     float foo(int); // expected-error {{functions that differ only in their return type cannot be overloaded}}
   }
 }

the foo(float) function declared at function scope should not hide the float(int)
while trying to redeclare functions.

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

llvm-svn: 272961
2016-06-16 21:39:46 +00:00