Commit Graph

2878 Commits

Author SHA1 Message Date
DeLesley Hutchins b570c13574 Consumed analysis: track function parameters.
Patch by chris.wailes@gmail.com.

llvm-svn: 189616
2013-08-29 22:36:05 +00:00
DeLesley Hutchins 7fa60edb47 Consumed analysis: non-const methods no longer transfer an object into an
unknown state.  Patch by chris.wailes@gmail.com.

llvm-svn: 189612
2013-08-29 21:17:25 +00:00
DeLesley Hutchins 5533ec5c55 Consumed analysis: improve handling of conditionals.
Patch by chris.wailes@gmail.com.

* The TestedVarsVisitor was folded into the ConsumedStmtVisitor.
* The VarTestResult class was updated to allow these changes.
* The PropagationInfo class was updated for the same reasons.
* Correctly handle short-circuiting of Boolean operations.
* Blocks are now marked as unreachable when we can statically prove we will
  never branch to them.
* Unreachable blocks are skipped by the analysis.

llvm-svn: 189594
2013-08-29 17:26:57 +00:00
David Majnemer 8918920a32 Sema: Subst type default template args earlier
Summary:
We would not perform substitution at an appropriate point, allowing strange
results to appear. We would accepts things that we shouldn't or mangle things incorrectly.  Note that this hasn't fixed the other cases like
template-template parameters or non-type template parameters.

Reviewers: doug.gregor, rjmccall, rsmith

Reviewed By: rsmith

CC: cfe-commits

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

llvm-svn: 189540
2013-08-28 23:48:32 +00:00
Eli Friedman a31efa07ff Improve error for assignment to incomplete class.
PR7681.

llvm-svn: 189510
2013-08-28 20:35:35 +00:00
Reid Kleckner 78af0708b7 Delete CC_Default and use the target default CC everywhere
Summary:
Makes functions with implicit calling convention compatible with
function types with a matching explicit calling convention.  This fixes
things like calls to qsort(), which has an explicit __cdecl attribute on
the comparator in Windows headers.

Clang will now infer the calling convention from the declarator.  There
are two cases when the CC must be adjusted during redeclaration:
1. When defining a non-inline static method.
2. When redeclaring a function with an implicit or mismatched
convention.

Fixes PR13457, and allows clang to compile CommandLine.cpp for the
Microsoft C++ ABI.

Excellent test cases provided by Alexander Zinenko!

Reviewers: rsmith

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

llvm-svn: 189412
2013-08-27 23:08:25 +00:00
Wei Pan 8d6b19a518 Handle predefined expression for a captured statement
- __func__ or __FUNCTION__ returns captured statement's parent
  function name, not the one compiler generated.

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

Reviewed by bkramer

llvm-svn: 189219
2013-08-26 14:27:34 +00:00
DeLesley Hutchins 73ec2ae91e Consumed analysis: change class name in test cases.
The name of a class used in the testing files was updated to actually
be descriptive.  Patch by chris.wailes@gmail.com.

llvm-svn: 189132
2013-08-23 18:40:39 +00:00
Richard Smith d136f60b07 Reword a diagnostic to avoid a confusing implication that it might be talking
about a declaration within a return type.

llvm-svn: 189083
2013-08-23 02:16:48 +00:00
DeLesley Hutchins c2ecf0d815 Update to consumed analysis.
Patch by chris.wailes@gmail.com.  The following functionality was added:

* The same functionality is now supported for both CXXOperatorCallExprs and CXXMemberCallExprs.
* Factored out some code in StmtVisitor.
* Removed variables from the state map when their destructors are encountered.
* Started adding documentation for the consumed analysis attributes.

llvm-svn: 189059
2013-08-22 20:44:47 +00:00
Larisse Voufo 8122b22adc Add a constexpr functionality test for static data member templates.
llvm-svn: 188975
2013-08-22 01:05:27 +00:00
Larisse Voufo 72caf2bb6b Refactor for clarity and simplicity.
llvm-svn: 188974
2013-08-22 00:59:14 +00:00
Larisse Voufo 4cda461ec4 Improve support for static data member templates. This revision still has at least one bug, as it does not respect the variable template specialization hierarchy well.
llvm-svn: 188969
2013-08-22 00:28:27 +00:00
Eli Friedman 5ba37d5282 Split isFromMainFile into two functions.
Basically, isInMainFile considers line markers, and isWrittenInMainFile
doesn't.  Distinguishing between the two is useful when dealing with
files which are preprocessed files or rewritten with -frewrite-includes
(so we don't, for example, print useless warnings).

llvm-svn: 188968
2013-08-22 00:27:10 +00:00
Nick Lewycky 1e43d9521f Fix the end sourcelocation of the call expression in a member access when
recovering by adding empty parenthesis. Fixes PR16676!

llvm-svn: 188920
2013-08-21 19:09:44 +00:00
Benjamin Kramer 90f5422954 Sema: Use the right type for PredefinedExpr when it's in a lambda.
1. We now print the return type of lambdas and return type deduced functions
as "auto". Trailing return types with decltype print the underlying type.
2. Use the lambda or block scope for the PredefinedExpr type instead of the
parent function. This fixes PR16946, a strange mismatch between type of the
expression and the actual result.
3. Verify the type in CodeGen.
4. The type for blocks is still wrong. They are numbered and the name is not
known until CodeGen.

llvm-svn: 188900
2013-08-21 11:45:27 +00:00
Richard Smith 3249fed9b2 If we find an error in the range expression in a range-based for loop, and the
loop variable has a type containing 'auto', set the declaration to be invalid
(because we couldn't deduce its type) to prevent follow-on errors.

llvm-svn: 188853
2013-08-21 01:40:36 +00:00
Richard Smith a6c8703e5b PR16727: don't try to evaluate a potentially value-dependent expression when
checking for missing parens in &&/|| expressions.

llvm-svn: 188716
2013-08-19 22:06:05 +00:00
Richard Smith f9b1510576 Refactor all diagnosing of TypoCorrections through a common function, in
preparation for teaching this function how to diagnose a correction that
includes importing a module.

llvm-svn: 188602
2013-08-17 00:46:16 +00:00
Rafael Espindola 87198cd35c Don't reject attribute used in an "extern const" variable definition.
Before this patch we would warn and drop the attribute in
extern const char test3[] __attribute__((used)) = "";

llvm-svn: 188588
2013-08-16 23:18:50 +00:00
DeLesley Hutchins d40542213c Thread safety analysis: new test case
llvm-svn: 188571
2013-08-16 18:28:00 +00:00
Eli Friedman 9ee175d8f0 Don't allow unary negation on scoped enums.
PR16900.

llvm-svn: 188511
2013-08-16 00:09:18 +00:00
DeLesley Hutchins 9f5193cf61 Thread Safety Analysis: fix bug when using TryLock with && and || expressions.
llvm-svn: 188505
2013-08-15 23:06:33 +00:00
Richard Smith c58f38f220 PR16875: The return type of a dependent function type is visible when it's
referenced as a member of the current instantiation. In that case, deduce the
type of the function to a dependent type rather than exposing an undeduced auto
type to the rest of the current instantiation.

The standard doesn't really say that the type is dependent in this case; I'll
bring this up with CWG.

llvm-svn: 188410
2013-08-14 20:16:31 +00:00
Larisse Voufo dbd6577964 Bug fix: note diagnosis on expression narrowing should say "variable template" instead of "static data member" when appropriate
llvm-svn: 188409
2013-08-14 20:15:02 +00:00
Larisse Voufo d8dd97c0a2 Bug fix: disallow a variable template to be redeclared as a non-templated variable
llvm-svn: 188350
2013-08-14 03:09:19 +00:00
Richard Smith 0d905476f8 Don't produce duplicate notes if we have deduction failure notes when resolving
the address of an overloaded function template.

llvm-svn: 188334
2013-08-14 00:00:44 +00:00
Eli Friedman 4e28b26589 sizeof(void) etc. should be a hard error in C++.
PR16872.

llvm-svn: 188324
2013-08-13 22:26:42 +00:00
Richard Smith 1c34fb78e7 Fix implementation of C11 6.2.7/4 and C++11 [dcl.array]p3:
When a local extern declaration redeclares some other entity, the type of that
entity is merged with the prior type if the prior declaration is visible (in C)
or is declared in the same scope (in C++).

 - Make LookupRedeclarationWithLinkage actually work in C++, use it in the right
   set of cases, and make it track whether it found a shadowed declaration.
 - Track whether we found a declaration in the same scope (for C++) including
   across serialization and template instantiation.

llvm-svn: 188307
2013-08-13 18:18:50 +00:00
Larisse Voufo a11bd8a7dc variable templates updated for PCH serialization... Still working on test cases...
llvm-svn: 188249
2013-08-13 02:02:26 +00:00
Eli Friedman 24b3fed69f Fix pretty-printing for unnamed unions.
This is just a couple of minor fixes to account for the existence
of ElaboratedType.

llvm-svn: 188209
2013-08-12 21:54:04 +00:00
Eli Friedman e2358c1deb Fix crash w/BlockDecl and invalid qualified decl.
I'm not really satisfied with the ad-hoc nature of
Sema::diagnoseQualifiedDeclaration, but I'm not sure how to fix it.

Fixes <rdar://problem/14639501>.

llvm-svn: 188208
2013-08-12 21:54:01 +00:00
DeLesley Hutchins 48a317663f Patch by Chris Wailes <chris.wailes@gmail.com>.
Reviewed by delesley, dblaikie.

Add the annotations and code needed to support a basic 'consumed' analysis.

Summary:
This new analysis is based on academic literature on linear types.  It tracks
the state of a value, either as unconsumed, consumed, or unknown.  Methods are
then annotated as CallableWhenUnconsumed, and when an annotated method is
called while the value is in the 'consumed' state a warning is issued.  A value
may be tested in the conditional statement of an if-statement; when this occurs
we know the state of the value in the different branches, and this information
is added to our analysis.  The code is still highly experimental, and the names
of annotations or the algorithm may be subject to change.

llvm-svn: 188206
2013-08-12 21:20:55 +00:00
Serge Pavlov b716b3ca1f Avoid spurious error messages if parent template class cannot be instantiated
Differential Revision: http://llvm-reviews.chandlerc.com/D924

llvm-svn: 188133
2013-08-10 05:54:47 +00:00
Richard Trieu 4b03d98858 Fix for PR16570: when comparing two function pointers, discard qualifiers when
comparing non-reference function parameters.  The qualifiers don't matter for
comparisons.

This is a re-commit of r187769, which was accidentially reverted in r187770,
with a simplification at the suggestion of Eli Friedman.

llvm-svn: 188112
2013-08-09 21:42:32 +00:00
Rafael Espindola 71eccb39b8 Fix alignof computation of large arrays on x86_64.
We were exposing the extra alignment given to large arrays. The new behavior
matches gcc, which is a good thing since this is a gcc extension.

Thanks to Joerg Sonnenberger for noticing it.

While at it, centralize the method description in the .h file.

llvm-svn: 187999
2013-08-08 19:53:46 +00:00
Richard Trieu 60a6a4c8ee Split the deprecated increment bool warning into a sub-group of -Wdeprecated
so that it can be toggled independently of other deprecated warnings.

llvm-svn: 187958
2013-08-08 03:05:52 +00:00
Richard Trieu 493df1a14f Emit an error for enum increments and decrements in C++ mode.
Fixes PR16394.

llvm-svn: 187955
2013-08-08 01:50:23 +00:00
Richard Trieu 4e7c962891 Add a new warning to -Wloop-analysis to detect suspicious increments or
decrements inside for loops.  Idea for this warning proposed in PR15636:

http://llvm.org/bugs/show_bug.cgi?id=15636

llvm-svn: 187817
2013-08-06 21:31:54 +00:00
Richard Smith 49ca8aab58 PR16755: When initializing or modifying a bitfield member in a constant
expression, truncate the stored value to the size of the bitfield.

llvm-svn: 187782
2013-08-06 07:09:20 +00:00
Larisse Voufo 4154f46c5a Fixing commit r187768: Moved diagnosis of forward declarations of variable templates from Parser to Sema.
llvm-svn: 187770
2013-08-06 03:57:41 +00:00
Richard Trieu 08d5085d43 Fix for PR16570: when comparing two function pointers, discard qualifiers when
comparing non-reference function parameters.  The qualifiers don't matter for
comparisons.

llvm-svn: 187769
2013-08-06 03:44:10 +00:00
Larisse Voufo 39a1e507ff Started implementing variable templates. Top level declarations should be fully supported, up to some limitations documented as FIXMEs or TODO. Static data member templates work very partially. Static data member templates of class templates need particular attention...
llvm-svn: 187762
2013-08-06 01:03:05 +00:00
Richard Smith d7293d7fcb Implement C++'s restrictions on the type of an expression passed to a vararg
function: it can't be 'void' and it can't be an initializer list. We give a
hard error for these rather than treating them as undefined behavior (we can
and probably should do the same for non-POD types in C++11, but as of this
change we don't).

Slightly rework the checking of variadic arguments in a function with a format
attribute to ensure that certain kinds of format string problem (non-literal
string, too many/too few arguments, ...) don't suppress this error.

llvm-svn: 187735
2013-08-05 18:49:43 +00:00
David Majnemer 1365781b5b Sema: Don't assume a nested name specifier holds a type
Sema::PerformObjectMemberConversion assumed that the Qualifier it was
given holds a type. However, the specifier could hold just a namespace.
In this case, we should ignore the qualifier and not attempt to cast to
it.

llvm-svn: 187715
2013-08-05 04:53:41 +00:00
Arnaud A. de Grandmaison cb6f943ada Check dynamic_cast is not used with -fno-rtti, unless it is a noop or can be resolved statically.
llvm-svn: 187564
2013-08-01 08:28:32 +00:00
Reid Kleckner a09e44c75d Fix declaring class template methods with an attributed typedef
This change unifies the logic for template instantiation of methods and
functions declared with typedefs.

It ensures that SubstFunctionType() always fills the Params out param
with non-null ParmVarDecls or returns null.

Reviewers: rsmith

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

llvm-svn: 187528
2013-07-31 21:00:18 +00:00
Kaelyn Uhrain 957c8b1c70 A few small cleanups to r187504. Thanks to dblaikie for the assist.
llvm-svn: 187521
2013-07-31 20:16:17 +00:00
Kaelyn Uhrain 0c51de4ab1 Improve the diagnostic experience, including adding recovery, for
changing '->' to '.' when there is no operator-> defined for a class.

llvm-svn: 187504
2013-07-31 17:38:24 +00:00
Richard Trieu 2ac682a671 Fix a crasher than manifests when typo correction suggests a function template.
llvm-svn: 187467
2013-07-31 00:48:10 +00:00