Commit Graph

18643 Commits

Author SHA1 Message Date
Chandler Carruth c41c8b3a4a Fix the warning for divide by zero to be a bit more robust. ;]
Previously, it only ever fired for zeros which formed null pointers.
Now, hilariously, in C++98 this was almost anything. Including tricks
like warning on the divisor in this code:

typedef char c3[3];
size_t f(c3* ptr) {
  return (sizeof(ptr) / sizeof(*ptr)) / (size_t)(!(sizeof(ptr) % sizeof(*ptr)));
}

Why the RHS of the outer divide is a null pointer constant is a sordid
tale of sorrow. Anyways, the committee fixed this for C++11 and onward
as part of core isssue 903, and Richard recently implemented this fix
causing the warning to go away here (and elsewhere).

This patch restores the warning here and adds it for numerous other
somewhat obvious gaffes:

int g(int x) {
  return x / (int)(0.0);
}

The patch is essentially just using the full power of our constant
folding in Clang to produce the warning, but insisting that it must fold
to an *integer* which is zero so that we don't get false positives
anywhere.

llvm-svn: 183970
2013-06-14 08:57:18 +00:00
Richard Smith a509f2fdfa Emit initializers for static-storage-duration temporaries as constants where
possible.

llvm-svn: 183967
2013-06-14 03:07:01 +00:00
Eli Friedman d4b6e7a9b7 Fix the linkage of static locals inside a CapturedStmt. (Found in the
process of trying to fix the related issue for block literals.)

llvm-svn: 183951
2013-06-13 21:50:44 +00:00
Eli Friedman ef10282a0f Followup to r183931 to fix the lambda conversion-to-block-pointer member.
llvm-svn: 183942
2013-06-13 20:56:27 +00:00
Eli Friedman 8f54e136f4 Fix a small bug in the linkage computation for the lambda conversion-to-function-pointer member.
llvm-svn: 183931
2013-06-13 19:39:48 +00:00
Rafael Espindola 3b3a166ce6 Allow clang to build __clear_cache on ARM.
__clear_cache is special. It needs no signature, but is a real function in
compiler_rt or libgcc.

Patch by Andrew Turner.

llvm-svn: 183926
2013-06-13 18:34:17 +00:00
Richard Smith 77ad7a2d3d Clean up test to appease NDEBUG builds.
llvm-svn: 183924
2013-06-13 18:07:12 +00:00
Richard Smith ab341c62b3 More for PR12457: fix handling of __builtin_isinf_sign and test.
llvm-svn: 183890
2013-06-13 06:31:13 +00:00
Richard Smith 8889a3d3b5 Towards PR12457: constant expression evaluation support for __builtin_parity{,l,ll}, __builtin_ffs{,l,ll}, and __builtin_fpclassify.
llvm-svn: 183889
2013-06-13 06:26:32 +00:00
Richard Smith 80b3c8e32f Fix part of PR12457. Patch by Justin Bogner!
llvm-svn: 183886
2013-06-13 05:04:16 +00:00
Richard Smith f24e6e747b Fix some confusing diagnostic wording. s/implicit default/implicit/ if we're
not actually talking about a default constructor.

llvm-svn: 183885
2013-06-13 03:34:55 +00:00
Richard Smith d577fbbd1c C++11: If a class has a user-declared copy operation or destructor, the
implicit definition of a copy operation is deprecated. Add a warning for this
to -Wdeprecated. This warning is disabled by default for now, pending
investigation into how common this situation is.

llvm-svn: 183884
2013-06-13 03:23:42 +00:00
Richard Smith 4055de40ab Implement core issue 903: only integer literals with value 0 and prvalues of
type std::nullptr_t are null pointer constants from C++11 onwards.

llvm-svn: 183883
2013-06-13 02:46:14 +00:00
Richard Smith f026b60099 In C++11, promote access declaration diagnostic from warning to error. There
doesn't seem to be any value in even adding a -W flag for this.

llvm-svn: 183882
2013-06-13 02:12:17 +00:00
Richard Smith 8ca78a16f4 Add -Wdeprecated warnings and fixits for things deprecated in C++11:
- 'register' storage class
 - dynamic exception specifications

Only the former check is enabled by default for now (the latter might be quite noisy).

llvm-svn: 183881
2013-06-13 02:02:51 +00:00
Richard Smith 2eabf78eb6 When copy-initializing a temporary for a reference binding, don't allow use of
explicit constructors.

llvm-svn: 183879
2013-06-13 00:57:57 +00:00
Nick Lewycky 2c308503ea Include the unexpanded packs in the initializer expression when checking a
pack expanded constructor initializer list. Fixes PR16303!

llvm-svn: 183878
2013-06-13 00:45:47 +00:00
Richard Smith 0603bbb53c Don't suggest putting 'operator new' or 'operator delete' in a namespace to fix a two-phase lookup issue. That's not permitted.
llvm-svn: 183874
2013-06-12 22:56:54 +00:00
Richard Smith cc1b96d356 PR12086, PR15117
Introduce CXXStdInitializerListExpr node, representing the implicit
construction of a std::initializer_list<T> object from its underlying array.
The AST representation of such an expression goes from an InitListExpr with a
flag set, to a CXXStdInitializerListExpr containing a MaterializeTemporaryExpr
containing an InitListExpr (possibly wrapped in a CXXBindTemporaryExpr).

This more detailed representation has several advantages, the most important of
which is that the new MaterializeTemporaryExpr allows us to directly model
lifetime extension of the underlying temporary array. Using that, this patch
*drastically* simplifies the IR generation of this construct, provides IR
generation support for nested global initializer_list objects, fixes several
bugs where the destructors for the underlying array would accidentally not get
invoked, and provides constant expression evaluation support for
std::initializer_list objects.

llvm-svn: 183872
2013-06-12 22:31:48 +00:00
Richard Smith e3b28bc363 Move detection of reference members binding to temporaries from building of
CXXCtorInitializers to the point where we perform the questionable lifetime
extension. This exposed a selection of false negatives in the warning.

llvm-svn: 183869
2013-06-12 21:51:50 +00:00
Richard Trieu 33a4b3db0d Introducing -Wheader-guard, a warning that checks header guards actually work
properly.  This warning checks that the #ifndef and #define directives at
the beginning of a header refer to the same macro name.  Includes a fix-it
hint to correct the header guard.

llvm-svn: 183867
2013-06-12 21:20:57 +00:00
Richard Smith 736a947bdc Reapply r183721, reverted in r183776, with a fix for a bug in the former (we
were lacking ExprWithCleanups nodes in some cases where the new approach to
lifetime extension needed them).

Original commit message:

Rework IR emission for lifetime-extended temporaries. Instead of trying to walk
into the expression and dig out a single lifetime-extended entity and manually
pull its cleanup outside the expression, instead keep a list of the cleanups
which we'll need to emit when we get to the end of the full-expression. Also
emit those cleanups early, as EH-only cleanups, to cover the case that the
full-expression does not terminate normally. This allows IR generation to
properly model temporary lifetime when multiple temporaries are extended by the
same declaration.

We have a pre-existing bug where an exception thrown from a temporary's
destructor does not clean up lifetime-extended temporaries created in the same
expression and extended to automatic storage duration; that is not fixed by
this patch.

llvm-svn: 183859
2013-06-12 20:42:33 +00:00
Eli Friedman c68dbeffe3 Fix buildbot breakage on PPC64.
llvm-svn: 183847
2013-06-12 17:31:32 +00:00
Eli Friedman f045007f11 Add support for complex compound assignments where the LHS is a scalar.
Fixes <rdar://problem/11224126> and PR12790.

llvm-svn: 183821
2013-06-12 01:40:06 +00:00
Eli Friedman 96fd264cc0 Make va_arg and argument passing to varargs functions work correctly with
AVX vectors when AVX is turned on.

Fixes <rdar://problem/10513611>.

llvm-svn: 183813
2013-06-12 00:13:45 +00:00
Eli Friedman 6cc05f7f01 Tweak r183791 so we don't print a note without a source location.
llvm-svn: 183803
2013-06-11 22:26:34 +00:00
Eli Friedman 1f16b743d9 Correctly handle designated initializers which modify an array initialized
with a string.  This case is sort of tricky because we can't modify the
StringLiteral used to represent such initializers.
We are forced to decompose the string into individual characters.

Fixes <rdar://problem/10465114>.

llvm-svn: 183791
2013-06-11 21:48:11 +00:00
Richard Smith 389790a270 Add a testcase for PR7434, which is a bug we no longer appear to have.
llvm-svn: 183787
2013-06-11 20:38:45 +00:00
Richard Smith 4a28f534e1 Revert r183721. It caused cleanups to be delayed too long in some cases.
Testcase to follow.

llvm-svn: 183776
2013-06-11 19:14:25 +00:00
David Majnemer 66ad574f40 Implement DR61: Address of ambiguous bound methods should be disallowed
DR61 affirms that expressions containing unresolved member access should
be disallowed when performing "address of" operations.

llvm-svn: 183723
2013-06-11 03:56:29 +00:00
David Majnemer 55890bfaa6 Implement DR85: Redeclaration of member is forbidden
Disallow the existence of a declaration of a member class that isn't a
forward declaration before it's definition.

llvm-svn: 183722
2013-06-11 03:51:23 +00:00
Richard Smith 7c5d4dce49 Rework IR emission for lifetime-extended temporaries. Instead of trying to walk
into the expression and dig out a single lifetime-extended entity and manually
pull its cleanup outside the expression, instead keep a list of the cleanups
which we'll need to emit when we get to the end of the full-expression. Also
emit those cleanups early, as EH-only cleanups, to cover the case that the
full-expression does not terminate normally. This allows IR generation to
properly model temporary lifetime when multiple temporaries are extended by the
same declaration.

We have a pre-existing bug where an exception thrown from a temporary's
destructor does not clean up lifetime-extended temporaries created in the same
expression and extended to automatic storage duration; that is not fixed by
this patch.

llvm-svn: 183721
2013-06-11 02:41:00 +00:00
Eli Friedman 2761350730 Fix a very silly mistake in r183590.
llvm-svn: 183720
2013-06-11 01:59:28 +00:00
Eli Friedman 61f615af81 Fix a FIXME in a testcase about packed structs and calls I left around
while fixing a related bug.  The fix here was simpler than I thought it
would be.

Fixes <rdar://problem/10530444>.

llvm-svn: 183718
2013-06-11 01:08:22 +00:00
Argyrios Kyrtzidis f0168de936 [libclang] Allow building a precompiled preamble with compiler errors
A while ago we allowed libclang to build a PCH that had compiler errors; this was to retain the performance
afforded by a PCH even if the user's code is in an intermediate state.

Extend this for the precompiled preamble as well.

rdar://14109828

llvm-svn: 183717
2013-06-11 00:36:55 +00:00
Fariborz Jahanian 286fcf6797 Objective-C [qoi]: Issue better warning when nsstring literal is missing
the '@'. PR16287 and // rdar://14106083

llvm-svn: 183713
2013-06-10 23:51:51 +00:00
Eli Friedman 4871a46cc3 Make sure we don't emit invalid IR for StmtExprs with complex cleanups.
Fixes <rdar://problem/14074868>.

llvm-svn: 183699
2013-06-10 22:04:49 +00:00
Richard Trieu bb4b894e0b Add a new warning, -Wlogical-not-parentheses, to -Wparentheses.
This warning triggers on the logical not of a non-boolean expression on the
left hand side of comparison.  Often, the user meant to negate the comparison,
not just the left hand side of the comparison.  Two notes are also emitted,
the first with a fix-it to add parentheses around the comparison, and the other
to put parenthesis around the not expression to silence the warning.

bool not_equal(int x, int y) {
  return !x == y;  // warn here
}

  return !(x == y);  // first fix-it, to negate comparison.

  return (!x) == y;  // second fix-it, to silence warning.

llvm-svn: 183688
2013-06-10 18:52:07 +00:00
Larisse Voufo 236bec24ec reverted test
llvm-svn: 183637
2013-06-10 06:50:24 +00:00
Faisal Vali 475671057c Fix the parser's updating of the template depth when parsing local templates and late-parsed templates.
This is a slight tweak of r180708; It avoids incrementing depth when non-template local classes nested within member templates of local classes are encountered.  
This patch was LGTM'd by Doug http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20130506/079656.html and passed the regression tests that normally pass (i.e. excluding many Module and Index tests on Windows that fail regardless)

llvm-svn: 183620
2013-06-08 19:47:52 +00:00
Faisal Vali 6a79ca1c6d Revert r183618.
I ran clang-format on my patch but it seemed to have wreaked havoc with new lines  - might have to do with using it on windows :( will resubmit once i've cleaned this issue up. sorry.

llvm-svn: 183619
2013-06-08 19:39:00 +00:00
Faisal Vali 9b629831a7 Fix the parser's updating of the template depth when parsing local templates and late-parsed templates. This is a slight tweak of r180708; It avoids incrementing depth when non-template local classes nested within member templates of local classes are encountered.
This patch was LGTM'd by Doug http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20130506/079656.html and passed the regression tests that normally pass (i.e. excluding many Module and Index tests on Windows that fail regardless)

llvm-svn: 183618
2013-06-08 19:33:09 +00:00
Reid Kleckner 88709c6952 Add a test case for blocks taking an array typedef
r183614 was failing because va_list on some platforms is defined in a
similar manner.  This test fails on Windows with r183614 applied.

llvm-svn: 183617
2013-06-08 18:51:21 +00:00
Reid Kleckner 17aeeeb311 Revert "[Sema] Make FunctionType's TSI use unadjusted argument types"
This reverts commit r183614.

It broke test/Sema/block-printf-attribute-1.c on non-Windows platforms,
and the fix is not trivial.

llvm-svn: 183616
2013-06-08 18:19:52 +00:00
Reid Kleckner 4c124ffd5b [Sema] Make FunctionType's TSI use unadjusted argument types
This helps preserve the type-as-written in the AST, which we need for
MSVC mangling.  In particular, we need to preserve the types of array
parameters in function pointer types.

The essence of this change is:
-  QualType ArgTy = Param->getType();
+  QualType ArgTy = Param->getTypeSourceInfo()->getType();

... followed by the adjustment in ActOnFunctionDeclarator().

Differential Revision: http://llvm-reviews.chandlerc.com/D883

llvm-svn: 183614
2013-06-08 17:28:56 +00:00
Serge Pavlov 89578fd439 Recognition of empty structures and unions is moved to semantic stage
Differential Revision: http://llvm-reviews.chandlerc.com/D586

llvm-svn: 183609
2013-06-08 13:29:58 +00:00
Jin-Gu Kang 0b5ca604a9 Added a type checking which handle the case of an ext vector and integral scalar
llvm-svn: 183602
2013-06-08 02:15:36 +00:00
Anna Zaks 22895473af [analyzer; alternate edges] Fix the edge locations in presence of macros.
We drew the diagnostic edges to wrong statements in cases the note was on a macro.
The fix is simple, but seems to work just fine for a whole bunch of test cases (plist-macros.cpp).

Also, removes an unnecessary edge in edges-new.mm, when function signature starts with a macro.

llvm-svn: 183599
2013-06-08 00:29:24 +00:00
Adrian Prantl 0ffce6ec99 Debug info: An if condition now creates a lexical scope of its own.
Two variables with the same name declared in two if conditions in the same
scope are no longer coalesced into one.

rdar://problem/14024005

llvm-svn: 183597
2013-06-08 00:16:55 +00:00
Richard Smith faadef7369 Recursively lifetime-extend into array temporaries. These can get implicitly
created through binding a reference-to-array to an initializer list.

llvm-svn: 183594
2013-06-08 00:02:08 +00:00