aboutsummaryrefslogtreecommitdiff
path: root/lib/StaticAnalyzer/Core/PathDiagnostic.cpp
diff options
context:
space:
mode:
authorAnna Zaks <ganna@apple.com>2011-09-15 18:56:07 +0000
committerAnna Zaks <ganna@apple.com>2011-09-15 18:56:07 +0000
commit4fdf97bf51d2a156cec3232efd6dae110aa02aa0 (patch)
tree7240de9e4106b186574f079a990100dc6227361b /lib/StaticAnalyzer/Core/PathDiagnostic.cpp
parent1a995ddaa53a20dcd063ea47eb1f533ecb0d243a (diff)
[analyzer] Refactor: make PathDiagnosticLocation responsible for validation of SourceLocations (commit 2 of ?):
- Fix a fixme and move the logic of creating a PathDiagnosticLocation corresponding to a ProgramPoint into a PathDiagnosticLocation constructor. - Rename PathDiagnosticLocation::create to differentiate from the added constructor. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@139825 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/StaticAnalyzer/Core/PathDiagnostic.cpp')
-rw-r--r--lib/StaticAnalyzer/Core/PathDiagnostic.cpp33
1 files changed, 26 insertions, 7 deletions
diff --git a/lib/StaticAnalyzer/Core/PathDiagnostic.cpp b/lib/StaticAnalyzer/Core/PathDiagnostic.cpp
index 8d53b2b380..8dcb03bc15 100644
--- a/lib/StaticAnalyzer/Core/PathDiagnostic.cpp
+++ b/lib/StaticAnalyzer/Core/PathDiagnostic.cpp
@@ -130,7 +130,31 @@ void PathDiagnosticClient::HandlePathDiagnostic(const PathDiagnostic *D) {
// PathDiagnosticLocation methods.
//===----------------------------------------------------------------------===//
-PathDiagnosticLocation PathDiagnosticLocation::create(const ExplodedNode* N,
+PathDiagnosticLocation::PathDiagnosticLocation(const LocationContext *lc,
+ const SourceManager &sm)
+ : K(RangeK), S(0), D(0), SM(&sm), LC(lc) {
+ SourceLocation L = LC->getDecl()->getBodyRBrace();
+ R = SourceRange(L, L);
+}
+
+PathDiagnosticLocation::PathDiagnosticLocation(const ProgramPoint& P,
+ const SourceManager &SMng)
+ : K(StmtK), S(0), D(0), SM(&SMng), LC(P.getLocationContext()) {
+
+ if (const BlockEdge *BE = dyn_cast<BlockEdge>(&P)) {
+ const CFGBlock *BSrc = BE->getSrc();
+ S = BSrc->getTerminatorCondition();
+ }
+ else if (const PostStmt *PS = dyn_cast<PostStmt>(&P)) {
+ S = PS->getStmt();
+ }
+
+ if (!S)
+ invalidate();
+}
+
+PathDiagnosticLocation PathDiagnosticLocation::createEndOfPath(
+ const ExplodedNode* N,
const SourceManager &SM) {
assert(N && "Cannot create a location with a null node.");
@@ -150,8 +174,7 @@ PathDiagnosticLocation PathDiagnosticLocation::create(const ExplodedNode* N,
NI = NI->succ_empty() ? 0 : *(NI->succ_begin());
}
- const Decl &D = N->getCodeDecl();
- return PathDiagnosticLocation(D.getBodyRBrace(), SM);
+ return PathDiagnosticLocation(N->getLocationContext(), SM);
}
static SourceLocation getValidSourceLocation(const Stmt* S,
@@ -188,10 +211,6 @@ FullSourceLoc PathDiagnosticLocation::asLocation() const {
return FullSourceLoc(D->getLocation(), const_cast<SourceManager&>(*SM));
}
- if (!R.isValid())
- return FullSourceLoc(LC->getDecl()->getBodyRBrace(),
- const_cast<SourceManager&>(*SM));
-
return FullSourceLoc(R.getBegin(), const_cast<SourceManager&>(*SM));
}