summaryrefslogtreecommitdiffstats
path: root/clang/test/SemaCXX/uninitialized.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Suppress false-positive -Wuninitialized warnings in the constructor of aRichard Smith2019-12-111-0/+9
| | | | templated but non-template class.
* [Sema] Remove location from implicit capture init exprVedant Kumar2018-09-131-2/+4
| | | | | | | | | | | | | | | | | | A lambda's closure is initialized when the lambda is declared. For implicit captures, the initialization code emitted from EmitLambdaExpr references source locations *within the lambda body* in the function containing the lambda. This results in a poor debugging experience: we step to the line containing the lambda, then into lambda, out again, over and over, until every capture's field is initialized. To improve stepping behavior, assign the starting location of the lambda to expressions which initialize an implicit capture within it. rdar://39807527 Differential Revision: https://reviews.llvm.org/D50927 llvm-svn: 342194
* Fix typos in clangAlexander Kornienko2018-04-061-6/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Found via codespell -q 3 -I ../clang-whitelist.txt Where whitelist consists of: archtype cas classs checkk compres definit frome iff inteval ith lod methode nd optin ot pres statics te thru Patch by luzpaz! (This is a subset of D44188 that applies cleanly with a few files that have dubious fixes reverted.) Differential revision: https://reviews.llvm.org/D44188 llvm-svn: 329399
* Switch from using a DiagnosticTrap and a note for "while defining a specialRichard Smith2017-05-251-1/+1
| | | | | | | | | | | | | | | | | | | | | | | member function" context notes to registering an entry on the context stack. Also reorder the steps within defining special members to be consistent. This has a few benefits: if multiple diagnostics are produced while checking such a member, the note is now attached to the first such diagnostic rather than the last, this prepares us for persisting these diagnostics between the point at which we require the implicit instantiation of a template and the point at which that instantiation is actually performed, and this fixes some cases where we would fail to produce a full note stack leading back to user code in the case of such a diagnostic. The reordering exposed a case where we could recursively attempt to define a defaulted destructor while we're already defining one (and other such cases also appear to be possible, with or without this change), so this change also reuses the "willHaveBody" flag on function declarations to track that we're in the middle of synthesizing a body for the function and bails out if we try to define a function that we're already defining. llvm-svn: 303930
* PR31631: fix bad CFG (and bogus warnings) when an if-statement has an ↵Richard Smith2017-01-131-1/+11
| | | | | | init-statement and has binary operator as its condition. llvm-svn: 291964
* [Sema] Add warning for unused lambda capturesMalcolm Parsons2017-01-131-1/+1
| | | | | | | | | | | | | | | Summary: Warn when a lambda explicitly captures something that is not used in its body. The warning is part of -Wunused and can be enabled with -Wunused-lambda-capture. Reviewers: rsmith, arphaman, jbcoe, aaron.ballman Subscribers: Quuxplusone, arphaman, cfe-commits Differential Revision: https://reviews.llvm.org/D28467 llvm-svn: 291905
* PR23334: Perform semantic checking of lambda capture initialization in the ↵Richard Smith2015-04-271-0/+9
| | | | | | | | | | | | | | | | | | right context. Previously we'd try to perform checks on the captures from the middle of parsing the lambda's body, at the point where we detected that a variable needed to be captured. This was wrong in a number of subtle ways. In PR23334, we couldn't correctly handle the list of potential odr-uses resulting from the capture, and our attempt to recover from that resulted in a use-after-free. We now defer building the initialization expression until we leave the lambda body and return to the enclosing context, where the initialization does the right thing. This patch only covers lambda-expressions, but we should apply the same change to blocks and captured statements too. llvm-svn: 235921
* Make -Wuninitialized warn on pointer-to-member and comma operators.Manuel Klimek2015-03-031-1/+44
| | | | | | | | | | | `isTrackedVar` has been updated to also track records. `DeclRefExpr`s appearing on the left side of a comma operator are ignored, while those appearing on the right side are classified as `Use`. Patch by Enrico Pertoso. llvm-svn: 231068
* When checking for uninitialized values, do not confuse "std::move" with everyRichard Trieu2014-11-271-0/+44
| | | | | | other function named "move". llvm-svn: 222863
* Extend -Wuninitialized to warn when accessing uninitialized base classes in aRichard Trieu2014-11-211-0/+39
| | | | | | constructor. llvm-svn: 222503
* Fix a bug where -Wuninitialized would skip arguments to a function call.Richard Trieu2014-11-011-1/+14
| | | | llvm-svn: 221030
* Have -Wuninitialized catch uninitalized use in overloaded operator arguments.Richard Trieu2014-10-311-0/+26
| | | | llvm-svn: 221000
* Disable the uninitialized field warning in uninstantiated classes.Richard Trieu2014-10-221-0/+43
| | | | | | | | If a templated class is not instantiated, then the AST for it could be missing some things that would throw the field checker off. Wait until specialization before emitting these warnings. llvm-svn: 220363
* Add support for initializer lists on field initializers for -WuninitializedRichard Trieu2014-10-171-1/+109
| | | | llvm-svn: 220087
* Improve -Wuninitialized warnings for fields that are record types.Richard Trieu2014-10-011-0/+93
| | | | | | | Get the record handling code from SelfReferenceChecker into UninitializedFieldVisitor as well as copying the testcases. llvm-svn: 218740
* Update uninitialized tests to ensure that field initialization has theRichard Trieu2014-09-301-29/+40
| | | | | | same coverage as the global checker. llvm-svn: 218720
* Update -Wuninitialized to be stricter on CK_NoOp casts.Richard Trieu2014-09-301-0/+16
| | | | llvm-svn: 218715
* Add back checking for condition of conditional operator for -WuninitializedRichard Trieu2014-09-261-1/+11
| | | | llvm-svn: 218556
* Add increment/decrement operators and compound assignment operators to theRichard Trieu2014-09-251-3/+39
| | | | | | uninitialized checkers that did not have them before. llvm-svn: 218435
* Fix an edge case with BinaryOperator's in -Wuninitialized. Add testcases forRichard Trieu2014-09-241-0/+16
| | | | | | the other visitors as well. llvm-svn: 218366
* Improve -Wuninitialized to take into account field ordering with initializerRichard Trieu2014-09-231-0/+53
| | | | | | | lists. Since the fields are inititalized one at a time, using a field with lower index to initialize a higher indexed field should not be warned on. llvm-svn: 218339
* Check delegating constructors for using uninitialized fields.Richard Trieu2014-09-121-0/+16
| | | | llvm-svn: 217716
* Stop double visiting some expressions during self reference checking.Richard Trieu2014-09-041-0/+6
| | | | | | | | Originally, self reference checking made a double pass over some expressions to handle reference type checking. Now, allow HandleValue to also check reference types, and fallback to Visit for unhandled expressions. llvm-svn: 217203
* During cross field uninitialized checking, when processing an assignment,Richard Trieu2014-08-281-0/+14
| | | | | | | | | | | | | | | | | | | | | | don't mark the field as initialized until the next initializer instead of instantly. Since this checker is AST based, statements are processed in tree order instead of following code flow. This can result in different warnings from just reordering the code. Also changed to use one checker per constructor instead of creating a new checker per field. class T { int x, y; // Already warns T(bool b) : x(!b ? (1 + y) : (y = 5)) {} // New warning added here, previously (1 + y) comes after (y = 5) in the AST // preventing the warning. T(bool b) : x(b ? (y = 5) : (1 + y)) {} }; llvm-svn: 216641
* More -Wuninitialized updatesRichard Trieu2014-08-271-4/+44
| | | | | | | | | | | Fix r216438 to catch more complicated self-initialized in std::move. For instance, "Foo f = std::move(cond ? OtherFoo : (UNUSED_VALUE, f));" Make sure that BinaryConditionalOperator, ConditionalOperator, BinaryOperator with comma operator, and OpaqueValueExpr perform the correct usage forwarding across the three uninitialized value checkers. llvm-svn: 216627
* Passing a variable to std::move now counts as a use for -WuninitializedRichard Trieu2014-08-261-2/+55
| | | | llvm-svn: 216438
* Improve -Wuninitialized to catch const classes being used in their own copyRichard Trieu2014-08-121-2/+22
| | | | | | constructors. llvm-svn: 215471
* Fix a tranche of comment, test and doc typosAlp Toker2013-12-051-1/+1
| | | | llvm-svn: 196510
* Simplify and refactor the uninitialized field warning.Richard Trieu2013-10-251-3/+63
| | | | | | | | | | | Change the uninitialized field warnings so that field initializers are checked inside the constructor. Previously, in class initializers were checked separately. Running one set of checks also simplifies the logic for preventing duplicate warnings. Added new checks to warn when an uninitialized field is used in base class initialization. Also fixed misspelling of uninitialized and moved all code for this warning together. llvm-svn: 193386
* Modify the uninitialized field visitor to detect uninitialized use across theRichard Trieu2013-09-201-2/+109
| | | | | | | | | | | | | | | | | | fields in the class. This allows a better checking of member intiailizers and in class initializers in regards to initialization ordering. For instance, this code will now produce warnings: class A { int x; int y; A() : x(y) {} // y is initialized after x, warn here A(int): y(x) {} // default initialization of leaves x uninitialized, warn here }; Several test cases were updated with -Wno-uninitialized to silence this warning. llvm-svn: 191068
* Refactor the uninitialized field visitor. Also moved the calls to the visitorRichard Trieu2013-09-131-0/+38
| | | | | | | later in the code so that the expressions will have addition processing first. This catches a few additional cases of uninitialized uses of class fields. llvm-svn: 190657
* PR15906: The body of a lambda is not an evaluated subexpression; don't visit ↵Richard Smith2013-05-031-0/+12
| | | | | | it when visiting such subexpressions. llvm-svn: 181046
* Handle CXXOperatorCallExpr when checking self referrnce during initialization ofRichard Trieu2013-03-261-0/+15
| | | | | | class types. llvm-svn: 177987
* Reapply r172878 with test case.Ted Kremenek2013-01-191-16/+16
| | | | llvm-svn: 172888
* -Wuninitialized: warn about uninitialized values resulting from ?: that ↵Ted Kremenek2013-01-191-4/+4
| | | | | | evaluate to lvalues (in C++). llvm-svn: 172875
* Change how the SelfReferenceChecker handles MemberExpr. Instead of treatingRichard Trieu2012-10-031-0/+63
| | | | | | | each one separately, process a stack of MemberExpr's as a single unit so that static calls and member access will not be warned on. llvm-svn: 165074
* Cleaning up the self initialization checker.Richard Trieu2012-10-011-0/+10
| | | | | | | | | | | -Allow Sema to do more processing on the initial Expr before checking it. -Remove the special conditions in HandleExpr() -Move the code so that only one call site is needed. -Removed the function from Sema and only call it locally. -Warn on potentially evaluated reference variables, not just casts to r-values. -Update tests. llvm-svn: 164951
* Make warnings about uninitialized fields include the field name.Hans Wennborg2012-09-211-25/+25
| | | | | | | | | | | This makes the wording more informative, and consistent with the other warnings about uninitialized variables. Also, me and David who reviewed this couldn't figure out why we would need to do a lookup to get the name of the variable; so just print the name directly. llvm-svn: 164366
* Warn about self references in in-class initializers.Hans Wennborg2012-09-181-1/+27
| | | | | | | | | | | | | | This makes Clang warn about self references in in-class initializers, for example: struct S { int a = a + 42; }; This basically just moves UninitializedFieldVisitor up a bit in SemaDeclCXX.cpp, and adds a call to it from ActOnCXXInClassMemberInitializer. llvm-svn: 164131
* Better wording for reference self-initialization warning.Hans Wennborg2012-08-201-3/+3
| | | | llvm-svn: 162198
* Warn about self-initialization of references.Hans Wennborg2012-08-171-0/+19
| | | | | | | Initializing a reference with itself, e.g. "int &a = a;" seems like a very bad idea. llvm-svn: 162093
* Check local static variables for self reference on initialization.Richard Trieu2012-08-141-0/+62
| | | | llvm-svn: 161909
* For global record types, the self reference checker was called twice, resultingRichard Trieu2012-08-061-0/+23
| | | | | | | in duplicate -Wuninitialized warnings. Change so that only the check in TryConstructorInitialization() will be used and a single warning be emitted. llvm-svn: 161345
* Refine CFG so that '&&' and '||' don't lead to extra confluence points when ↵Ted Kremenek2012-07-141-1/+1
| | | | | | | | | | | | | | | | | | used in a branch, but instead push the terminator for the branch down into the basic blocks of the subexpressions of '&&' and '||' respectively. This eliminates some artifical control-flow from the CFG and results in a more compact CFG. Note that this patch only alters the branches 'while', 'if' and 'for'. This was complex enough for one patch. The remaining branches (e.g., do...while) can be handled in a separate patch, but they weren't immediately tackled because they were less important. It is possible that this patch introduces some subtle bugs, particularly w.r.t. to destructor placement. I've tried to audit these changes, but it is also known that the destructor logic needs some refinement in the area of '||' and '&&' regardless (i.e., their are known bugs). llvm-svn: 160218
* Use a proper visitor to recursively check for uninitialized use in constructors.Richard Trieu2012-06-141-3/+83
| | | | llvm-svn: 158477
* Removing the lambda extension warning concerning single return statements, ↵Aaron Ballman2012-06-041-1/+1
| | | | | | as it no longer applies. llvm-svn: 157943
* Pull some cases of initialization with self-reference warnings out ofRichard Trieu2012-05-091-3/+42
| | | | | | -Wconditional-uninitialized into -Wuninitialized. llvm-svn: 156512
* Update the SelfReferenceChecker. Refactored some of the visitor methods.Richard Trieu2012-05-091-1/+8
| | | | | | | Added support for conditional operators and tightened the exclusion of the unary operator from all operators to only the address of operator. llvm-svn: 156450
* Add -Wuninitialized test for C++11 lambdas.Ted Kremenek2012-04-121-1/+6
| | | | llvm-svn: 154608
* Fix broken CFG when an initializer is a statement expression that starts ↵Ted Kremenek2012-03-221-0/+15
| | | | | | with a while loop (PR 12325). llvm-svn: 153242
OpenPOWER on IntegriCloud