summaryrefslogtreecommitdiffstats
path: root/clang/lib/StaticAnalyzer/Core/PathDiagnostic.cpp
diff options
context:
space:
mode:
authorAnna Zaks <ganna@apple.com>2011-09-20 18:23:52 +0000
committerAnna Zaks <ganna@apple.com>2011-09-20 18:23:52 +0000
commit83128bc101cd0b2417f8bd7ed86a948f37c704b7 (patch)
tree14378d39263ba5a82af90f8dfac4cd8d670a59f5 /clang/lib/StaticAnalyzer/Core/PathDiagnostic.cpp
parent0486db08bdd570ccfabf09f72e6aaf9dee3090d6 (diff)
downloadbcm5719-llvm-83128bc101cd0b2417f8bd7ed86a948f37c704b7.tar.gz
bcm5719-llvm-83128bc101cd0b2417f8bd7ed86a948f37c704b7.zip
[analyzer] Refactor PathDiagnosticLocation: Use PointerUnion of LocationContext and AnalysisContext to support creation of PathDiagnosticLocations for checkers which no context sensitivity.
llvm-svn: 140162
Diffstat (limited to 'clang/lib/StaticAnalyzer/Core/PathDiagnostic.cpp')
-rw-r--r--clang/lib/StaticAnalyzer/Core/PathDiagnostic.cpp25
1 files changed, 16 insertions, 9 deletions
diff --git a/clang/lib/StaticAnalyzer/Core/PathDiagnostic.cpp b/clang/lib/StaticAnalyzer/Core/PathDiagnostic.cpp
index 1d03b669970..b8a811a6e18 100644
--- a/clang/lib/StaticAnalyzer/Core/PathDiagnostic.cpp
+++ b/clang/lib/StaticAnalyzer/Core/PathDiagnostic.cpp
@@ -131,16 +131,23 @@ void PathDiagnosticClient::HandlePathDiagnostic(const PathDiagnostic *D) {
//===----------------------------------------------------------------------===//
static SourceLocation getValidSourceLocation(const Stmt* S,
- const LocationContext *LC) {
+ LocationOrAnalysisContext LAC) {
SourceLocation L = S->getLocStart();
+ assert(!LAC.isNull() && "A valid LocationContext or AnalysisContext should "
+ "be passed to PathDiagnosticLocation upon creation.");
// S might be a temporary statement that does not have a location in the
// source code, so find an enclosing statement and use it's location.
if (!L.isValid()) {
- const ParentMap &PM = LC->getParentMap();
+
+ ParentMap *PM = 0;
+ if (LAC.is<const LocationContext*>())
+ PM = &LAC.get<const LocationContext*>()->getParentMap();
+ else
+ PM = &LAC.get<AnalysisContext*>()->getParentMap();
while (!L.isValid()) {
- S = PM.getParent(S);
+ S = PM->getParent(S);
L = S->getLocStart();
}
}
@@ -151,8 +158,8 @@ static SourceLocation getValidSourceLocation(const Stmt* S,
PathDiagnosticLocation
PathDiagnosticLocation::createBeginStmt(const Stmt *S,
const SourceManager &SM,
- const LocationContext *LC) {
- return PathDiagnosticLocation(getValidSourceLocation(S, LC),
+ LocationOrAnalysisContext LAC) {
+ return PathDiagnosticLocation(getValidSourceLocation(S, LAC),
SM, SingleLocK);
}
@@ -246,7 +253,7 @@ PathDiagnosticLocation PathDiagnosticLocation::createSingleLocation(
}
FullSourceLoc
- PathDiagnosticLocation::genLocation(const LocationContext *LC) const {
+ PathDiagnosticLocation::genLocation(LocationOrAnalysisContext LAC) const {
assert(isValid());
// Note that we want a 'switch' here so that the compiler can warn us in
// case we add more cases.
@@ -255,7 +262,7 @@ FullSourceLoc
case RangeK:
break;
case StmtK:
- return FullSourceLoc(getValidSourceLocation(S, LC),
+ return FullSourceLoc(getValidSourceLocation(S, LAC),
const_cast<SourceManager&>(*SM));
case DeclK:
return FullSourceLoc(D->getLocation(), const_cast<SourceManager&>(*SM));
@@ -265,7 +272,7 @@ FullSourceLoc
}
PathDiagnosticRange
- PathDiagnosticLocation::genRange(const LocationContext *LC) const {
+ PathDiagnosticLocation::genRange(LocationOrAnalysisContext LAC) const {
assert(isValid());
// Note that we want a 'switch' here so that the compiler can warn us in
// case we add more cases.
@@ -300,7 +307,7 @@ PathDiagnosticRange
case Stmt::BinaryConditionalOperatorClass:
case Stmt::ConditionalOperatorClass:
case Stmt::ObjCForCollectionStmtClass: {
- SourceLocation L = getValidSourceLocation(S, LC);
+ SourceLocation L = getValidSourceLocation(S, LAC);
return SourceRange(L, L);
}
}
OpenPOWER on IntegriCloud