diff options
author | Anna Zaks <ganna@apple.com> | 2011-09-14 00:25:17 +0000 |
---|---|---|
committer | Anna Zaks <ganna@apple.com> | 2011-09-14 00:25:17 +0000 |
commit | 2c65eea947d9de6ac412a92891b158d85bcd6b01 (patch) | |
tree | 84610208f0838a8aa9e66b00847b16b0973d5f8d /clang/lib/StaticAnalyzer/Core/PathDiagnostic.cpp | |
parent | 1b2a65ca3a7fe00b503bf56ae613d084f45b12ab (diff) | |
download | bcm5719-llvm-2c65eea947d9de6ac412a92891b158d85bcd6b01.tar.gz bcm5719-llvm-2c65eea947d9de6ac412a92891b158d85bcd6b01.zip |
[analyzer] Refactor: Make PathDiagnosticLocation responsible for creating a valid object given an ExploadedNode (the same logic can be reused by other checkers).
llvm-svn: 139672
Diffstat (limited to 'clang/lib/StaticAnalyzer/Core/PathDiagnostic.cpp')
-rw-r--r-- | clang/lib/StaticAnalyzer/Core/PathDiagnostic.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/clang/lib/StaticAnalyzer/Core/PathDiagnostic.cpp b/clang/lib/StaticAnalyzer/Core/PathDiagnostic.cpp index e56f1572e92..28a6d403f59 100644 --- a/clang/lib/StaticAnalyzer/Core/PathDiagnostic.cpp +++ b/clang/lib/StaticAnalyzer/Core/PathDiagnostic.cpp @@ -12,6 +12,7 @@ //===----------------------------------------------------------------------===// #include "clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h" +#include "clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h" #include "clang/AST/Expr.h" #include "clang/AST/Decl.h" #include "clang/AST/DeclObjC.h" @@ -128,6 +129,30 @@ void PathDiagnosticClient::HandlePathDiagnostic(const PathDiagnostic *D) { // PathDiagnosticLocation methods. //===----------------------------------------------------------------------===// +PathDiagnosticLocation PathDiagnosticLocation::create(const ExplodedNode* N, + const SourceManager &SM) { + assert(N && "Cannot create a location with a null node."); + + const ExplodedNode *NI = N; + + while (NI) { + ProgramPoint P = NI->getLocation(); + + if (const StmtPoint *PS = dyn_cast<StmtPoint>(&P)) { + return PathDiagnosticLocation(PS->getStmt(), SM); + } + else if (const BlockEdge *BE = dyn_cast<BlockEdge>(&P)) { + const Stmt *Term = BE->getSrc()->getTerminator(); + assert(Term); + return PathDiagnosticLocation(Term, SM); + } + NI = NI->succ_empty() ? 0 : *(NI->succ_begin()); + } + + const Decl &D = N->getCodeDecl(); + return PathDiagnosticLocation(D.getBodyRBrace(), SM); +} + FullSourceLoc PathDiagnosticLocation::asLocation() const { assert(isValid()); // Note that we want a 'switch' here so that the compiler can warn us in |