summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/AnalysisBasedWarnings.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Thread-safety analysis: adding in a basic lockset tracking system. ThisCaitlin Sadowski2011-08-231-0/+561
| | | | | | | | | | | | | | | | system flags an error when unlocking a lock which was not held, locking the same lock twice, having a different lockset on each iteration of a loop, or going out of scope while still holding a lock. In order to successfully use the lockset, this patch also makes sure that attribute arguments are attached correctly for later parsing. This patch was also worked on by DeLesley Hutchins. Note: This patch has been reviewed by Chandler Carruth and Jeffrey Yasskin. Feel free to provide post-commit review comments for a subsequent patch. llvm-svn: 138350
* remove unneeded llvm:: namespace qualifiers on some core types now that ↵Chris Lattner2011-07-231-4/+4
| | | | | | | | LLVM.h imports them into the clang namespace. llvm-svn: 135852
* Move duplicate uninitialized warning suppression into theChandler Carruth2011-07-221-7/+5
| | | | | | | | | | | | AnalysisBasedWarnings Sema layer and out of the Analysis library itself. This returns the uninitialized values analysis to a more pure form, allowing its original logic to correctly detect some categories of definitely uninitialized values. Fixes PR10358 (again). Thanks to Ted for reviewing and updating this patch after his rewrite of several portions of this analysis. llvm-svn: 135748
* Simplify passing of CFGBuildOptions around for AnalysisContext. No ↵Ted Kremenek2011-07-211-10/+16
| | | | | | functionality change. llvm-svn: 135666
* Reduce -Wuninitialized time by 22% (on sqlite) by removing the recursive AST ↵Ted Kremenek2011-07-191-0/+14
| | | | | | | | | | | | | | | crawl. This is accomplished by forcing the needed expressions for -Wuninitialized to always be CFGElements in the CFG. This allows us to remove a fair amount of the code for -Wuninitialized. Some fallout: - AnalysisBasedWarnings.cpp now specifically toggles the CFGBuilder to create a CFG that is suitable for -Wuninitialized. This is a layering violation, since the logic for -Wuninitialized is in libAnalysis. This can be fixed with the proper refactoring. - Some of the source locations for -Wunreachable-code warnings have shifted. While not ideal, this is okay because that analysis already needs some serious reworking. llvm-svn: 135480
* Zero this struct in a way that neither depends on the size of the struct nor ↵Benjamin Kramer2011-07-161-0/+1
| | | | | | triggers warnings from GCC. llvm-svn: 135351
* Remove a gcc warning.Fariborz Jahanian2011-07-161-1/+1
| | | | llvm-svn: 135348
* Initialize all the AnalysisBasedWarnings statistics to zero.Benjamin Kramer2011-07-081-1/+7
| | | | | | Found by valgrind. llvm-svn: 134733
* Based on comments from Chris, switch to using CFG::getNumBlockIDs()Chandler Carruth2011-07-061-3/+2
| | | | | | | | | | | | | rather than a computed std::distance(). At some point I had convinced myself that these two were different; but as far as I can tell on re-exampination they aren't, and the number of block IDs is actually just a count of the blocks in the CFG. While this removes the primary motivation for guarding all of this with CollectStats, I have a patch coming up that will almost certainly make it important again. llvm-svn: 134552
* Build up statistics about the work done for analysis based warnings.Chandler Carruth2011-07-061-2/+66
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Special detail is added for uninitialized variable analysis as this has serious performance problems than need to be tracked. Computing some of this data is expensive, for example walking the CFG to determine its size. To avoid doing that unless the stats data is going to be used, we thread a bit into the Sema object to track whether detailed stats should be collected or not. This bit is used to avoid computations whereever the computations are likely to be more expensive than checking the state of the flag. Thus, counters are in some cases unconditionally updated, but the more expensive (and less frequent) aggregation steps are skipped. With this patch, we're able to see that for 'gcc.c': *** Analysis Based Warnings Stats: 232 functions analyzed (0 w/o CFGs). 7151 CFG blocks built. 30 average CFG blocks per function. 1167 max CFG blocks per function. 163 functions analyzed for uninitialiazed variables 640 variables analyzed. 3 average variables per function. 94 max variables per function. 96409 block visits. 591 average block visits per function. 61546 max block visits per function. And for the reduced testcase in PR10183: *** Analysis Based Warnings Stats: 98 functions analyzed (0 w/o CFGs). 8526 CFG blocks built. 87 average CFG blocks per function. 7277 max CFG blocks per function. 68 functions analyzed for uninitialiazed variables 1359 variables analyzed. 19 average variables per function. 1196 max variables per function. 2540494 block visits. 37360 average block visits per function. 2536495 max block visits per function. That last number is the somewhat scary one that indicates the problem in PR10183. llvm-svn: 134494
* When producing -Wuninitialized Fix-Its for pointers, prefer " = NULL"Douglas Gregor2011-07-021-1/+9
| | | | | | over "= 0". Fixes <rdar://problem/9714386>. llvm-svn: 134302
* Teach CFG building how to deal with CXXMemberCallExprs and BoundMemberTy,John McCall2011-05-111-1/+6
| | | | | | | then teach -Wreturn-type to handle the same. Net effect: we now correctly handle noreturn attributes on member calls in the CFG. llvm-svn: 131178
* Simplify the tracking of when to issue a fixit hint, making the helperChandler Carruth2011-04-051-13/+18
| | | | | | | | function more clear and obvious in behavior. Add some comments documenting the behavior of the primary diagnostic helper. llvm-svn: 128901
* Separate the logic for issuing the initialization fixit hint from theChandler Carruth2011-04-051-4/+10
| | | | | | | diagnostic emission. The fixit hint, when suggested, typically has nothing to do with the nature or form of the reference. llvm-svn: 128899
* Begin refactoring the uninitialized warning code that I uglied up. ThisChandler Carruth2011-04-051-91/+94
| | | | | | | | | | | | | extracts a function to handle the emission of the diagnostic separately from the walking over the set of uninitialized uses. Also updates the naming used within this extracted function to be a bit more consistent with the rest of Clang's naming patterns. The next step will be breaking this apart so that we can go through different functions rather than tracking so many boolean variables. llvm-svn: 128898
* Fix PR9624 by explicitly disabling uninitialized warnings for direct self-init:Chandler Carruth2011-04-051-17/+28
| | | | | | | | | | | | | | | int x = x; GCC disables its warnings on this construct as a way of indicating that the programmer intentionally wants the variable to be uninitialized. Only the warning on the initializer is turned off in this iteration. This makes the code a lot more ugly, but starts commenting the surprising behavior here. This is a WIP, I want to refactor it substantially for clarity, and to determine whether subsequent warnings should be suppressed or not. llvm-svn: 128894
* Cleanup the style of some of this code prior to functional changes.Chandler Carruth2011-04-051-25/+28
| | | | | | | | | I think this moves the code in the desired direction of the new style recommendations (and style conventional in Clang), but if anyone prefers the previous style, or has other suggestions just chime in and I'll follow up. llvm-svn: 128878
* Fix PR 9626 (duplicated self-init warnings under -Wuninitialized) with ↵Ted Kremenek2011-04-041-9/+21
| | | | | | | | | | | | | | numerous CFG and UninitializedValues analysis changes: 1) Change the CFG to include the DeclStmt for conditional variables, instead of using the condition itself as a faux DeclStmt. 2) Update ExprEngine (the static analyzer) to understand (1), so not to regress. 3) Update UninitializedValues.cpp to initialize all tracked variables to Uninitialized at the start of the function/method. 4) Only use the SelfReferenceChecker (SemaDecl.cpp) on global variables, leaving the dataflow analysis to handle other cases. The combination of (1) and (3) allows the dataflow-based -Wuninitialized to find self-init problems when the initializer contained control-flow. llvm-svn: 128858
* -Wuninitialized: use "self-init" warning when issue uninitialized values ↵Ted Kremenek2011-04-041-2/+45
| | | | | | warnings from the dataflow analysis that include within the initializer of a variable. llvm-svn: 128843
* -Wuninitialized: don't issue fixit for initializer if a variable declaration ↵Ted Kremenek2011-04-041-0/+4
| | | | | | already has an initializer. llvm-svn: 128838
* Rename class 'CFGReachabilityAnalysis' to 'CFGReverseBlockReachabilityAnalysis'.Ted Kremenek2011-03-191-1/+1
| | | | | | | | | This rename serves two purposes: - It reflects the actual functionality of this analysis. - We will have more than one reachability analysis. llvm-svn: 127930
* Don't construct two CFGs just to run -Wuninitialized. While this causes new ↵Ted Kremenek2011-03-171-18/+1
| | | | | | | | warnings to be flagged under -Wconditional-uninitialized, this is something we can improve over time. llvm-svn: 127802
* Split warnings from -Wuninitialized-experimental into "must-be-initialized" ↵Ted Kremenek2011-03-151-0/+2
| | | | | | and "may-be-initialized" warnings, each controlled by different flags. llvm-svn: 127669
* Split warnings from -Wuninitialized-experimental into "must-be-initialized" ↵Ted Kremenek2011-03-151-10/+18
| | | | | | and "may-be-initialized" warnings, each controlled by different flags. llvm-svn: 127666
* Rename UninitializedValuesV2 to UninitializedValues.Ted Kremenek2011-03-151-1/+1
| | | | llvm-svn: 127657
* When doing reachability analysis for warnings issued under ↵Ted Kremenek2011-03-101-14/+30
| | | | | | | | | DiagRuntimeBehavior, don't construct a ParentMap or CFGStmtMap. Instead, create a small set of Stmt* -> CFGBlock* mappings during CFG construction for only the statements we care about relating to the diagnostics we want to check for reachability. llvm-svn: 127396
* Teach CFGImplicitDtor::getDestructorDecl() about arrays of objects with ↵Ted Kremenek2011-03-031-1/+1
| | | | | | destructors. llvm-svn: 126910
* Introduce CFGImplicitDtor::isNoReturn() to query whether a destructor ↵Ted Kremenek2011-03-021-0/+15
| | | | | | actually returns. Use this for -Wreturn-type to prune false positives reported in PR 6884. llvm-svn: 126875
* Enhance Sema::DiagRuntimeBehavior() to delay some diagnostics to see if the ↵Ted Kremenek2011-02-231-3/+47
| | | | | | | | | | related code is reachable. This suppresses some diagnostics that occur in unreachable code (e.g., -Warray-bound). We only pay the cost of doing the reachability analysis when we issue one of these diagnostics. llvm-svn: 126290
* Have IdempotentOperationsChecker pull its CFGStmtMap from AnalysisContext.Ted Kremenek2011-02-231-0/+1
| | | | llvm-svn: 126288
* Issue AnalysisBasedWarnings as part of calling ↵Ted Kremenek2011-02-231-23/+4
| | | | | | Sema::PopBlockOrFunctionScope(). No real functionality change. llvm-svn: 126287
* Don't suggest -Wuninitialized fixits for uninitialized enum types.Ted Kremenek2011-02-051-1/+3
| | | | llvm-svn: 124924
* Based on user feedback, swap -Wuninitialized diagnostics to have the warning ↵Ted Kremenek2011-02-021-32/+37
| | | | | | refer to the bad use, and the note to the variable declaration. llvm-svn: 124758
* Add temporary hack to -Wuninitialize to create a separate CFG (for C++ code) ↵Ted Kremenek2011-02-011-1/+18
| | | | | | | | | | | | | that doesn't include implicit dtors. Implicit dtors confuse the ad hoc path-sensitivity of UninitializedValuesV2.cpp. This isn't the ideal solution, as it will directly impact compile time, but should significantly reduce the noise of -Wuninitialized on some code bases. This immediately "fixes" the false positive reported in PR 9063, although this isn't the right fix in the long run. llvm-svn: 124667
* Tweak -Wuninitialized fixit for '_Bool' types to be initialized to 0, and ↵Ted Kremenek2011-01-271-1/+1
| | | | | | C++ 'bool' types to false. llvm-svn: 124356
* Teach -Wuninitialized to suggest "= false" for initializing bool variables.Ted Kremenek2011-01-271-0/+3
| | | | llvm-svn: 124352
* Teach -Wreturn-type that destructors can appearTed Kremenek2011-01-261-11/+14
| | | | | | | | | after a 'return' in a CFGBlock. This accidentally was working before, but the false assumption that 'return' always appeared at the end of the block was uncovered by a recent change. llvm-svn: 124280
* Fix regression in -Wreturn-type caused by notTed Kremenek2011-01-251-12/+3
| | | | | | | | | | handling all CFGElement kinds. While writing the test case, it turned out that return-noreturn.cpp wasn't actually testing anything since it has the wrong -W flag. That uncovered another regression with the handling of destructors marked noreturn. WIP. llvm-svn: 124238
* Teach -Wuninitialized-experimental to also warnTed Kremenek2011-01-251-10/+17
| | | | | | about uninitialized variables captured by blocks. llvm-svn: 124213
* Provide -Wuninitialized-experimental fixitsTed Kremenek2011-01-211-3/+10
| | | | | | | for floats, and also check if 'nil' is declared when suggesting it for initializing ObjC pointers. llvm-svn: 124004
* Add basic fixits for -Wuninitialized-experimentalTed Kremenek2011-01-211-1/+20
| | | | | | | to suggest initializations for pointer and ObjC pointer types. llvm-svn: 123995
* Enhance -Wuninitialized-experimental diagnosticsTed Kremenek2011-01-211-3/+51
| | | | | | | | to issue the warning at an uninitialized variable's declaration, but to issue notes at possible uninitialized uses (which could be multiple). llvm-svn: 123994
* Teach UninitializedValuesV2 to implicitly reason about C++Ted Kremenek2011-01-181-7/+3
| | | | | | | | references by monitoring whether an access to a variable is solely to compute it's lvalue or to do an lvalue-to-rvalue conversion (i.e., a load). llvm-svn: 123777
* Handle base and member destructors in CheckFallThrough.Anders Carlsson2011-01-171-1/+10
| | | | llvm-svn: 123667
* Fix a bug where the -Wmissing-noreturn would always treat constructors with ↵Anders Carlsson2011-01-161-0/+6
| | | | | | base or member initializers as noreturn. llvm-svn: 123603
* Add initial prototype for implementation ofTed Kremenek2011-01-151-0/+30
| | | | | | -Wuninitialized based on CFG dataflow analysis. WIP. llvm-svn: 123512
* Remove a kludge from analysis based warnings that used to detectChandler Carruth2011-01-081-14/+2
| | | | | | | | | | | | | | | | temporaries with no-return destructors. The CFG now properly supports temporaries and implicit destructors which both makes this kludge no longer work, and conveniently removes the need for it. Turn on CFG handling of implicit destructors and initializers. Several ad-hoc benchmarks don't indicate any measurable performance impact from growing the CFG, and it fixes real correctness problems with warnings. As a result of turning on these CFG elements, we started to tickle an inf-loop in the unreachable code logic used for warnings. The fix is trivial. llvm-svn: 123056
* Fix diagnostic pragmas.Argyrios Kyrtzidis2010-12-151-9/+16
| | | | | | | | | | | | Diagnostic pragmas are broken because we don't keep track of the diagnostic state changes and we only check the current/latest state. Problems manifest if a diagnostic is emitted for a source line that has different diagnostic state than the current state; this can affect a lot of places, like C++ inline methods, template instantiations, the lexer, etc. Fix the issue by having the Diagnostic object keep track of the source location of the pragmas so that it is able to know what is the diagnostic state at any given source location. Fixes rdar://8365684. llvm-svn: 121873
* Rename CXXExprWithTemporaries -> ExprWithCleanups; there's no theoreticalJohn McCall2010-12-061-1/+1
| | | | | | reason this is limited to C++, and it's certainly not limited to temporaries. llvm-svn: 120996
* Introduce new CFGElement hierarchy to support C++ CFG, based on Marcin's patchZhongxing Xu2010-09-161-1/+5
| | | | | | and discussions with Ted and Jordy. llvm-svn: 114056
OpenPOWER on IntegriCloud