summaryrefslogtreecommitdiffstats
path: root/clang/lib/Analysis/PathDiagnostic.cpp
Commit message (Collapse)AuthorAgeFilesLines
* [analyzer] PR43102: Fix an assertion and an out-of-bounds error for ↵Kristof Umann2019-09-181-7/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | diagnostic location construction Summary: https://bugs.llvm.org/show_bug.cgi?id=43102 In today's edition of "Is this any better now that it isn't crashing?", I'd like to show you a very interesting test case with loop widening. Looking at the included test case, it's immediately obvious that this is not only a false positive, but also a very bad bug report in general. We can see how the analyzer mistakenly invalidated `b`, instead of its pointee, resulting in it reporting a null pointer dereference error. Not only that, the point at which this change of value is noted at is at the loop, rather then at the method call. It turns out that `FindLastStoreVisitor` works correctly, rather the supplied explodedgraph is faulty, because `BlockEdge` really is the `ProgramPoint` where this happens. {F9855739} So it's fair to say that this needs improving on multiple fronts. In any case, at least the crash is gone. Full ExplodedGraph: {F9855743} Reviewers: NoQ, xazax.hun, baloghadamsoftware, Charusso, dcoughlin, rnkovacs, TWeaver Subscribers: JesperAntonsson, uabelho, Ka-Ka, bjope, whisperity, szepet, a.sidorin, mikhail.ramalho, donat.nagy, dkrupp, gamesh411, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D66716 llvm-svn: 372269
* [analyzer][NFC] Fix inconsistent references to checkers as "checks"Kristof Umann2019-09-121-2/+2
| | | | | | | | | | | | | | Traditionally, clang-tidy uses the term check, and the analyzer uses checker, but in the very early years, this wasn't the case, and code originating from the early 2010's still incorrectly refer to checkers as checks. This patch attempts to hunt down most of these, aiming to refer to checkers as checkers, but preserve references to callback functions (like checkPreCall) as checks. Differential Revision: https://reviews.llvm.org/D67140 llvm-svn: 371760
* [analyzer] NFC: Move PathDiagnostic classes to libAnalysis.Artem Dergachev2019-09-111-0/+1215
| | | | | | | | | | | | At this point the PathDiagnostic, PathDiagnosticLocation, PathDiagnosticPiece structures no longer rely on anything specific to Static Analyzer, so we can move them out of it for everybody to use. PathDiagnosticConsumers are still to be handed off. Differential Revision: https://reviews.llvm.org/D67419 llvm-svn: 371661
* Split libAnalysis into two libraries: libAnalysis and libChecker.Ted Kremenek2010-01-251-281/+0
| | | | | | | | | | | | | | | | | | | | | | | | | (1) libAnalysis is a generic analysis library that can be used by Sema. It defines the CFG, basic dataflow analysis primitives, and inexpensive flow-sensitive analyses (e.g. LiveVariables). (2) libChecker contains the guts of the static analyzer, incuding the path-sensitive analysis engine and domain-specific checks. Now any clients that want to use the frontend to build their own tools don't need to link in the entire static analyzer. This change exposes various obvious cleanups that can be made to the layout of files and headers in libChecker. More changes pending. :) This change also exposed a layering violation between AnalysisContext and MemRegion. BlockInvocationContext shouldn't explicitly know about BlockDataRegions. For now I've removed the BlockDataRegion* from BlockInvocationContext (removing context-sensitivity; although this wasn't used yet). We need to have a better way to extend BlockInvocationContext (and any LocationContext) to add context-sensitivty. llvm-svn: 94406
* Switch PathDiagnostic to StringRef.Benjamin Kramer2009-12-111-36/+13
| | | | llvm-svn: 91155
* Reintroduce FoldingSet profiling for PathDiagnostics.Ted Kremenek2009-09-181-0/+62
| | | | llvm-svn: 82299
* Revert most of r82198, which was causing a large number of crashesTed Kremenek2009-09-181-62/+0
| | | | | | | | | | when running the analyzer on real projects. We'll keep the change to AnalysisManager.cpp in r82198 so that -fobjc-gc analyzes code correctly in both GC and non-GC modes, although this may emit two diagnostics for each bug in some cases (a better solution will come later). llvm-svn: 82201
* Introduce caching of diagnostics in BugReporter. This provides extraTed Kremenek2009-09-181-0/+62
| | | | | | | | | | | | | | | | | | | | | | | | | | | pruning of diagnostics that may be emitted multiple times. This is accomplished by adding FoldingSet profiling support to PathDiagnostic, and then having BugReporter record what diagnostics have been issued. This was motived to a serious bug introduced by moving the 'divide-by-zero' checking outside of GRExprEngine into a separate 'Checker' class. When analyzing code using the '-fobjc-gc' option, a given function would be analyzed twice, but the second time various "internal checks" would be disabled to avoid emitting multiple diagnostics (e.g., "null dereference") for the same issue. The problem is that such checks also effect path pruning and don't just emit diagnostics. This resulted in an assertion failure involving a real divide-by-zero in some analyzed code where we would get an assertion failure in APInt because the 'DivZero' check was disabled and didn't prune the logic that resulted in the divide-by-zero in the analyzer. The implemented solution is somewhat of a hack, and may not perform extremely well. This will need to be cleaned up over time. As a regression test, 'misc-ps.m' has been modified so that its tests are run using -fobjc-gc to test this diagnostic pruning behavior. llvm-svn: 82198
* Eliminate FunctionDecl::getBodyIfAvailableDouglas Gregor2009-09-121-1/+1
| | | | llvm-svn: 81588
* Remove tabs, and whitespace cleanups.Mike Stump2009-09-091-16/+16
| | | | llvm-svn: 81346
* Remove '#include <sstream>' from libAnalysis.Ted Kremenek2009-06-261-1/+1
| | | | llvm-svn: 74245
* PathDiagnosticLocation::asRange(): for a PathDiagnosticLocation, the range ↵Ted Kremenek2009-05-151-0/+9
| | | | | | | | of a DeclStmt is only the decl, not the decl + initializer. llvm-svn: 71831
* Implement function-try-blocks. However, there's a very subtle bug that I ↵Sebastian Redl2009-04-261-2/+7
| | | | | | can't track down. llvm-svn: 70155
* Add PathDiagnosticRange to PathDiagnostics. These simply wrap SourceRange andTed Kremenek2009-04-221-2/+3
| | | | | | | indicate whether or not the range represents an absolute range or should be extended by lexing to the end of the token. llvm-svn: 69834
* PathDiagnosticLocation: ranges for terminators now only include the firstTed Kremenek2009-04-221-1/+22
| | | | | | | | character instead of the entire range for the IfStmt, ForStmt, etc. We may gradually refine these ranges later, but basically terminator ranges just refer to the first keyword. llvm-svn: 69812
* FunctionDecl::getBody() is getting an ASTContext argument for use inDouglas Gregor2009-04-181-2/+7
| | | | | | | | lazy PCH deserialization. Propagate that argument wherever it needs to be. No functionality change, except that I've tightened up a few PCH tests in preparation. llvm-svn: 69406
* PathDiagnosticLocation now also wraps Decls.Ted Kremenek2009-04-061-6/+36
| | | | llvm-svn: 68470
* - Changed PathDiagnosticPiece::getLocation() to return a PathDiagnosticLocationTed Kremenek2009-04-011-0/+2
| | | | | | | | | instead of a FullSourceLoc. This resulted in a bunch of small edits in various clients. - Updated BugReporter to include an alternate PathDiagnostic generation algorithm for PathDiagnosticClients desiring more control-flow pieces. llvm-svn: 68193
* - Add class PathDiagosticLocationPair.Ted Kremenek2009-03-261-2/+2
| | | | | | - Have PathDiagnosticControlFlowPiece use a vector of PathDiagnosticLocationPairs to represent transitions. llvm-svn: 67786
* Implement PathDiagnosticLocation::asRange() and ↵Ted Kremenek2009-03-261-0/+15
| | | | | | PathDiagnosticLocation::asStmt(). llvm-svn: 67777
* Add comment.Ted Kremenek2009-03-261-0/+2
| | | | llvm-svn: 67776
* Restructure code to silence bogus GCC warning.Ted Kremenek2009-03-261-1/+3
| | | | llvm-svn: 67775
* - Implement PathDiagnosticLocation::asLocation.Ted Kremenek2009-03-261-0/+15
| | | | | | | - Switch PathDiagnosticEventPiece and PathDiagnosticMacroPiece to use PathDiagnosticLocation. llvm-svn: 67774
* PathDiagnostics (analyzer):Ted Kremenek2009-03-261-18/+6
| | | | | | | | | | | - Added a new class, 'PathDiagnosticLocation', that is a variant for SourceLocation, SourceRange, or Stmt*. This will be used soon by PathDiagnosticPieces to describe locations for targets of branches, locations of events, etc. - Did some prep. refactoring of PathDiagnosticPieces to prepare them for adopting the new PathDiagnosticLocation llvm-svn: 67767
* PathDiagnostics:Ted Kremenek2009-03-121-0/+7
| | | | | | | | | | | | | | | | - PathDiagnosticControlFlowPiece now consists of a "start" and "end" location to indicating the branch location and where the branch goes. BugReporter: - Updated BugReporter to construct PathDiagnosticControlFlowPiece objects with "end" locations. PlistDiagnostics: - Plists now contain the bug "type" (not just bug "category") - Plists now encode control-flow pieces differently than events; now the "start" and "end" locations are recorded llvm-svn: 66818
* BugReporter:Ted Kremenek2009-03-101-0/+26
| | | | | | | | | | | | - Group control flow and event PathDiagnosticPieces into PathDiagnosticMacroPieces. - Afterwards, eliminate any PathDiagnosticMacroPieces from a PathDiagnostic that contain no informative events. HTMLDiagnostics: - Use new information about PathDiagnosticMacroPieces to specially format message bubbles for macro expansions containing interesting events. llvm-svn: 66524
* Create PathDiagnosticPiece subclasses PathDiagnosticEventPiece andTed Kremenek2009-03-061-1/+3
| | | | | | | | PathDiagnosticControlFlowPiece to distinguish (in the class hierarchy) between events and control-flow diagnostic pieces. Clients must now use these directly when constructing PathDiagnosticPieces. llvm-svn: 66310
* Start work on subclassing PathDiagnosticPiece to distinguish more between ↵Ted Kremenek2009-03-061-0/+6
| | | | | | control-flow pieces, events, etc. llvm-svn: 66291
* Fix regression: initialize 'size' for PathDiagnostic to 0.Ted Kremenek2009-03-061-4/+14
| | | | | | Add some assertions along the way... llvm-svn: 66265
* Like PathDiagnosticPieces, strip trailing periods at the end of ↵Ted Kremenek2009-03-061-0/+14
| | | | | | PathDiagnostic descriptions llvm-svn: 66263
* For now, do not output the 'DisplayHint' in plist files.Ted Kremenek2009-03-021-4/+4
| | | | llvm-svn: 65860
* PathDiagnosticPiece now automatically strips off trailing periods in ↵Ted Kremenek2009-02-261-0/+27
| | | | | | diagnostic messages. llvm-svn: 65574
* Introduce code modification hints into the diagnostics system. When weDouglas Gregor2009-02-261-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | know how to recover from an error, we can attach a hint to the diagnostic that states how to modify the code, which can be one of: - Insert some new code (a text string) at a particular source location - Remove the code within a given range - Replace the code within a given range with some new code (a text string) Right now, we use these hints to annotate diagnostic information. For example, if one uses the '>>' in a template argument in C++98, as in this code: template<int I> class B { }; B<1000 >> 2> *b1; we'll warn that the behavior will change in C++0x. The fix is to insert parenthese, so we use code insertion annotations to illustrate where the parentheses go: test.cpp:10:10: warning: use of right-shift operator ('>>') in template argument will require parentheses in C++0x B<1000 >> 2> *b1; ^ ( ) Use of these annotations is partially implemented for HTML diagnostics, but it's not (yet) producing valid HTML, which may be related to PR2386, so it has been #if 0'd out. In this future, we could consider hooking this mechanism up to the rewriter to actually try to fix these problems during compilation (or, after a compilation whose only errors have fixes). For now, however, I suggest that we use these code modification hints whenever we can, so that we get better diagnostics now and will have better coverage when we find better ways to use this information. This also fixes PR3410 by placing the complaint about missing tokens just after the previous token (rather than at the location of the next token). llvm-svn: 65570
* Ensure that we assert if given an unhandled value.Mike Stump2009-02-071-0/+1
| | | | llvm-svn: 64004
* handle fatal errors, rely on warnings to point out missing cases.Chris Lattner2009-02-061-1/+2
| | | | llvm-svn: 63913
* remove a dead enumChris Lattner2008-11-221-1/+0
| | | | llvm-svn: 59879
* rewrite FormatDiagnostic to be less gross and a lot more efficient.Chris Lattner2008-11-191-3/+6
| | | | | | | This also makes it illegal to have bare '%'s in diagnostics. If you want a % in a diagnostic, use %%. llvm-svn: 59596
* This reworks some of the Diagnostic interfaces a bit to change how diagnosticsChris Lattner2008-11-181-16/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | are formed. In particular, a diagnostic with all its strings and ranges is now packaged up and sent to DiagnosticClients as a DiagnosticInfo instead of as a ton of random stuff. This has the benefit of simplifying the interface, making it more extensible, and allowing us to do more checking for things like access past the end of the various arrays passed in. In addition to introducing DiagnosticInfo, this also substantially changes how Diagnostic::Report works. Instead of being passed in all of the info required to issue a diagnostic, Report now takes only the required info (a location and ID) and returns a fresh DiagnosticInfo *by value*. The caller is then free to stuff strings and ranges into the DiagnosticInfo with the << operator. When the dtor runs on the DiagnosticInfo object (which should happen at the end of the statement), the diagnostic is actually emitted with all of the accumulated information. This is a somewhat tricky dance, but it means that the accumulated DiagnosticInfo is allowed to keep pointers to other expression temporaries without those pointers getting invalidated. This is just the minimal change to get this stuff working, but this will allow us to eliminate the zillions of variant "Diag" methods scattered throughout (e.g.) sema. For example, instead of calling: Diag(BuiltinLoc, diag::err_overload_no_match, typeNames, SourceRange(BuiltinLoc, RParenLoc)); We will soon be able to just do: Diag(BuiltinLoc, diag::err_overload_no_match) << typeNames << SourceRange(BuiltinLoc, RParenLoc)); This scales better to support arbitrary types being passed in (not just strings) in a type-safe way. Go operator overloading?! llvm-svn: 59502
* Change the diagnostics interface to take an array of pointers to Chris Lattner2008-11-181-1/+1
| | | | | | | | strings instead of array of strings. This reduces string copying in some not-very-important cases, but paves the way for future improvements. llvm-svn: 59494
* cleanups and simplifications.Chris Lattner2008-11-181-11/+7
| | | | llvm-svn: 59491
* * Remove isInSystemHeader() from DiagClient, move it to SourceManagerNico Weber2008-08-101-13/+1
| | | | | | | | | | | | | | | | * Move FormatError() from TextDiagnostic up to DiagClient, remove now empty class TextDiagnostic * Make DiagClient optional for Diagnostic This fixes the following problems: * -html-diags (and probably others) does now output the same set of warnings as console clang does * nothing crashes if one forgets to call setHeaderSearch() on TextDiagnostic * some code duplication is removed llvm-svn: 54620
* PathDiagnosticClients now retain ownership of passed PathDiagnostics, requiringTed Kremenek2008-04-221-2/+2
| | | | | | | | | | them to not be stack-allocated. HTMLDiagnostics now batches PathDiagnostics before emitting HTML in its dtor. This is a workaround for a problem when we trampled the Preprocessor state when highlighting macros (sometimes resulting in an assertion failure). llvm-svn: 50102
* PathDiagnosticPiece no longer contains a vector of strings; just one string.Ted Kremenek2008-03-271-7/+29
| | | | | | PathDiagnostic no longer contains a diagnostic ID or diagnostic level. llvm-svn: 48864
* Added classes "PathDiagnosticPiece", "PathDiagnostic", and ↵Ted Kremenek2008-03-271-0/+52
"PathDiagnosticClient", which encapsulate diagnostic reporting for paths. llvm-svn: 48861
OpenPOWER on IntegriCloud