[cfe-commits] r161277 - /cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp
Jordan Rose
jordan_rose at apple.com
Fri Aug 3 16:08:44 PDT 2012
Author: jrose
Date: Fri Aug 3 18:08:44 2012
New Revision: 161277
URL: http://llvm.org/viewvc/llvm-project?rev=161277&view=rev
Log:
[analyzer] Provide useful PathDiagnosticLocations for CallEnter/Exit events.
Modified:
cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp
Modified: cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp?rev=161277&r1=161276&r2=161277&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp Fri Aug 3 18:08:44 2012
@@ -276,6 +276,44 @@
return L;
}
+static PathDiagnosticLocation
+getLocationForCaller(const StackFrameContext *SFC,
+ const LocationContext *CallerCtx,
+ const SourceManager &SM) {
+ const CFGBlock &Block = *SFC->getCallSiteBlock();
+ CFGElement Source = Block[SFC->getIndex()];
+
+ switch (Source.getKind()) {
+ case CFGElement::Invalid:
+ llvm_unreachable("Invalid CFGElement");
+ case CFGElement::Statement:
+ return PathDiagnosticLocation(cast<CFGStmt>(Source).getStmt(),
+ SM, CallerCtx);
+ case CFGElement::Initializer: {
+ const CFGInitializer &Init = cast<CFGInitializer>(Source);
+ return PathDiagnosticLocation(Init.getInitializer()->getInit(),
+ SM, CallerCtx);
+ }
+ case CFGElement::AutomaticObjectDtor: {
+ const CFGAutomaticObjDtor &Dtor = cast<CFGAutomaticObjDtor>(Source);
+ return PathDiagnosticLocation::createEnd(Dtor.getTriggerStmt(),
+ SM, CallerCtx);
+ }
+ case CFGElement::BaseDtor:
+ case CFGElement::MemberDtor: {
+ const AnalysisDeclContext *CallerInfo = CallerCtx->getAnalysisDeclContext();
+ if (const Stmt *CallerBody = CallerInfo->getBody())
+ return PathDiagnosticLocation::createEnd(CallerBody, SM, CallerCtx);
+ return PathDiagnosticLocation::create(CallerInfo->getDecl(), SM);
+ }
+ case CFGElement::TemporaryDtor:
+ llvm_unreachable("not yet implemented!");
+ }
+
+ llvm_unreachable("Unknown CFGElement kind");
+}
+
+
PathDiagnosticLocation
PathDiagnosticLocation::createBegin(const Decl *D,
const SourceManager &SM) {
@@ -360,6 +398,19 @@
else if (const PostStmt *PS = dyn_cast<PostStmt>(&P)) {
S = PS->getStmt();
}
+ else if (const PostImplicitCall *PIE = dyn_cast<PostImplicitCall>(&P)) {
+ return PathDiagnosticLocation(PIE->getLocation(), SMng);
+ }
+ else if (const CallEnter *CE = dyn_cast<CallEnter>(&P)) {
+ return getLocationForCaller(CE->getCalleeContext(),
+ CE->getLocationContext(),
+ SMng);
+ }
+ else if (const CallExitEnd *CEE = dyn_cast<CallExitEnd>(&P)) {
+ return getLocationForCaller(CEE->getCalleeContext(),
+ CEE->getLocationContext(),
+ SMng);
+ }
return PathDiagnosticLocation(S, SMng, P.getLocationContext());
}
@@ -516,43 +567,6 @@
// Manipulation of PathDiagnosticCallPieces.
//===----------------------------------------------------------------------===//
-static PathDiagnosticLocation
-getLocationForCaller(const StackFrameContext *SFC,
- const LocationContext *CallerCtx,
- const SourceManager &SM) {
- const CFGBlock &Block = *SFC->getCallSiteBlock();
- CFGElement Source = Block[SFC->getIndex()];
-
- switch (Source.getKind()) {
- case CFGElement::Invalid:
- llvm_unreachable("Invalid CFGElement");
- case CFGElement::Statement:
- return PathDiagnosticLocation(cast<CFGStmt>(Source).getStmt(),
- SM, CallerCtx);
- case CFGElement::Initializer: {
- const CFGInitializer &Init = cast<CFGInitializer>(Source);
- return PathDiagnosticLocation(Init.getInitializer()->getInit(),
- SM, CallerCtx);
- }
- case CFGElement::AutomaticObjectDtor: {
- const CFGAutomaticObjDtor &Dtor = cast<CFGAutomaticObjDtor>(Source);
- return PathDiagnosticLocation::createEnd(Dtor.getTriggerStmt(),
- SM, CallerCtx);
- }
- case CFGElement::BaseDtor:
- case CFGElement::MemberDtor: {
- const AnalysisDeclContext *CallerInfo = CallerCtx->getAnalysisDeclContext();
- if (const Stmt *CallerBody = CallerInfo->getBody())
- return PathDiagnosticLocation::createEnd(CallerBody, SM, CallerCtx);
- return PathDiagnosticLocation::create(CallerInfo->getDecl(), SM);
- }
- case CFGElement::TemporaryDtor:
- llvm_unreachable("not yet implemented!");
- }
-
- llvm_unreachable("Unknown CFGElement kind");
-}
-
PathDiagnosticCallPiece *
PathDiagnosticCallPiece::construct(const ExplodedNode *N,
const CallExitEnd &CE,
More information about the cfe-commits
mailing list