aboutsummaryrefslogtreecommitdiff
path: root/lib/Analysis/PathDiagnostic.cpp
AgeCommit message (Collapse)Author
2010-01-25Split libAnalysis into two libraries: libAnalysis and libChecker.Ted Kremenek
(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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@94406 91177308-0d34-0410-b5e6-96231b3b80d8
2009-12-11Switch PathDiagnostic to StringRef.Benjamin Kramer
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@91155 91177308-0d34-0410-b5e6-96231b3b80d8
2009-09-18Reintroduce FoldingSet profiling for PathDiagnostics.Ted Kremenek
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@82299 91177308-0d34-0410-b5e6-96231b3b80d8
2009-09-18Revert most of r82198, which was causing a large number of crashesTed Kremenek
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). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@82201 91177308-0d34-0410-b5e6-96231b3b80d8
2009-09-18Introduce caching of diagnostics in BugReporter. This provides extraTed Kremenek
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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@82198 91177308-0d34-0410-b5e6-96231b3b80d8
2009-09-12Eliminate FunctionDecl::getBodyIfAvailableDouglas Gregor
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@81588 91177308-0d34-0410-b5e6-96231b3b80d8
2009-09-09Remove tabs, and whitespace cleanups.Mike Stump
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@81346 91177308-0d34-0410-b5e6-96231b3b80d8
2009-06-26Remove '#include <sstream>' from libAnalysis.Ted Kremenek
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@74245 91177308-0d34-0410-b5e6-96231b3b80d8
2009-05-15PathDiagnosticLocation::asRange(): for a PathDiagnosticLocation, the range ↵Ted Kremenek
of a DeclStmt is only the decl, not the decl + initializer. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@71831 91177308-0d34-0410-b5e6-96231b3b80d8
2009-04-26Implement function-try-blocks. However, there's a very subtle bug that I ↵Sebastian Redl
can't track down. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@70155 91177308-0d34-0410-b5e6-96231b3b80d8
2009-04-22Add PathDiagnosticRange to PathDiagnostics. These simply wrap SourceRange andTed Kremenek
indicate whether or not the range represents an absolute range or should be extended by lexing to the end of the token. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@69834 91177308-0d34-0410-b5e6-96231b3b80d8
2009-04-22PathDiagnosticLocation: ranges for terminators now only include the firstTed Kremenek
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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@69812 91177308-0d34-0410-b5e6-96231b3b80d8
2009-04-18FunctionDecl::getBody() is getting an ASTContext argument for use inDouglas Gregor
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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@69406 91177308-0d34-0410-b5e6-96231b3b80d8
2009-04-06PathDiagnosticLocation now also wraps Decls.Ted Kremenek
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@68470 91177308-0d34-0410-b5e6-96231b3b80d8
2009-04-01- Changed PathDiagnosticPiece::getLocation() to return a PathDiagnosticLocationTed Kremenek
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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@68193 91177308-0d34-0410-b5e6-96231b3b80d8
2009-03-26- Add class PathDiagosticLocationPair.Ted Kremenek
- Have PathDiagnosticControlFlowPiece use a vector of PathDiagnosticLocationPairs to represent transitions. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67786 91177308-0d34-0410-b5e6-96231b3b80d8
2009-03-26Implement PathDiagnosticLocation::asRange() and ↵Ted Kremenek
PathDiagnosticLocation::asStmt(). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67777 91177308-0d34-0410-b5e6-96231b3b80d8
2009-03-26Add comment.Ted Kremenek
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67776 91177308-0d34-0410-b5e6-96231b3b80d8
2009-03-26Restructure code to silence bogus GCC warning.Ted Kremenek
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67775 91177308-0d34-0410-b5e6-96231b3b80d8
2009-03-26- Implement PathDiagnosticLocation::asLocation.Ted Kremenek
- Switch PathDiagnosticEventPiece and PathDiagnosticMacroPiece to use PathDiagnosticLocation. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67774 91177308-0d34-0410-b5e6-96231b3b80d8
2009-03-26PathDiagnostics (analyzer):Ted Kremenek
- 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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67767 91177308-0d34-0410-b5e6-96231b3b80d8
2009-03-12PathDiagnostics:Ted Kremenek
- 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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66818 91177308-0d34-0410-b5e6-96231b3b80d8
2009-03-10BugReporter:Ted Kremenek
- 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66524 91177308-0d34-0410-b5e6-96231b3b80d8
2009-03-06Create PathDiagnosticPiece subclasses PathDiagnosticEventPiece andTed Kremenek
PathDiagnosticControlFlowPiece to distinguish (in the class hierarchy) between events and control-flow diagnostic pieces. Clients must now use these directly when constructing PathDiagnosticPieces. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66310 91177308-0d34-0410-b5e6-96231b3b80d8
2009-03-06Start work on subclassing PathDiagnosticPiece to distinguish more between ↵Ted Kremenek
control-flow pieces, events, etc. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66291 91177308-0d34-0410-b5e6-96231b3b80d8
2009-03-06Fix regression: initialize 'size' for PathDiagnostic to 0.Ted Kremenek
Add some assertions along the way... git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66265 91177308-0d34-0410-b5e6-96231b3b80d8
2009-03-06Like PathDiagnosticPieces, strip trailing periods at the end of ↵Ted Kremenek
PathDiagnostic descriptions git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66263 91177308-0d34-0410-b5e6-96231b3b80d8
2009-03-02For now, do not output the 'DisplayHint' in plist files.Ted Kremenek
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65860 91177308-0d34-0410-b5e6-96231b3b80d8
2009-02-26PathDiagnosticPiece now automatically strips off trailing periods in ↵Ted Kremenek
diagnostic messages. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65574 91177308-0d34-0410-b5e6-96231b3b80d8
2009-02-26Introduce code modification hints into the diagnostics system. When weDouglas Gregor
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). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65570 91177308-0d34-0410-b5e6-96231b3b80d8
2009-02-07Ensure that we assert if given an unhandled value.Mike Stump
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64004 91177308-0d34-0410-b5e6-96231b3b80d8
2009-02-06handle fatal errors, rely on warnings to point out missing cases.Chris Lattner
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@63913 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-22remove a dead enumChris Lattner
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59879 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-19rewrite FormatDiagnostic to be less gross and a lot more efficient.Chris Lattner
This also makes it illegal to have bare '%'s in diagnostics. If you want a % in a diagnostic, use %%. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59596 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-18This reworks some of the Diagnostic interfaces a bit to change how diagnosticsChris Lattner
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?! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59502 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-18Change the diagnostics interface to take an array of pointers to Chris Lattner
strings instead of array of strings. This reduces string copying in some not-very-important cases, but paves the way for future improvements. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59494 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-18cleanups and simplifications.Chris Lattner
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59491 91177308-0d34-0410-b5e6-96231b3b80d8
2008-08-10* Remove isInSystemHeader() from DiagClient, move it to SourceManagerNico Weber
* 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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@54620 91177308-0d34-0410-b5e6-96231b3b80d8
2008-04-22PathDiagnosticClients now retain ownership of passed PathDiagnostics, requiringTed Kremenek
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). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@50102 91177308-0d34-0410-b5e6-96231b3b80d8
2008-03-27PathDiagnosticPiece no longer contains a vector of strings; just one string.Ted Kremenek
PathDiagnostic no longer contains a diagnostic ID or diagnostic level. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@48864 91177308-0d34-0410-b5e6-96231b3b80d8
2008-03-27Added classes "PathDiagnosticPiece", "PathDiagnostic", and ↵Ted Kremenek
"PathDiagnosticClient", which encapsulate diagnostic reporting for paths. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@48861 91177308-0d34-0410-b5e6-96231b3b80d8