]> granicus.if.org Git - clang/commitdiff
[analyzer] Diagnostics: Supply Caller information even if the bug occurs
authorAnna Zaks <ganna@apple.com>
Wed, 14 Mar 2012 18:58:28 +0000 (18:58 +0000)
committerAnna Zaks <ganna@apple.com>
Wed, 14 Mar 2012 18:58:28 +0000 (18:58 +0000)
in the callee.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@152734 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h
lib/StaticAnalyzer/Core/BugReporter.cpp
lib/StaticAnalyzer/Core/PathDiagnostic.cpp
test/Analysis/inline-plist.c

index e98d82bf22b01a72d1be17d59187ac8e20163bbf..1599924e4aea08c68ab877a128ebec5f4fdbfe58 100644 (file)
@@ -391,11 +391,17 @@ class PathDiagnosticCallPiece : public PathDiagnosticPiece {
     : PathDiagnosticPiece(Call), Caller(callerD),
       Callee(0), callReturn(callReturnPos) {}
 
-  PathDiagnosticCallPiece(PathPieces &oldPath)
-    : PathDiagnosticPiece(Call), Caller(0), Callee(0), path(oldPath) {}
+  PathDiagnosticCallPiece(PathPieces &oldPath, const Decl *caller)
+    : PathDiagnosticPiece(Call), Caller(caller), Callee(0),
+      NoExit(true), path(oldPath) {}
   
   const Decl *Caller;
   const Decl *Callee;
+
+  // Flag signifying that this diagnostic has only call enter and no matching
+  // call exit.
+  bool NoExit;
+
 public:
   PathDiagnosticLocation callEnter;
   PathDiagnosticLocation callEnterWithin;
@@ -429,7 +435,8 @@ public:
                                             const CallExit &CE,
                                             const SourceManager &SM);
   
-  static PathDiagnosticCallPiece *construct(PathPieces &pieces);
+  static PathDiagnosticCallPiece *construct(PathPieces &pieces,
+                                            const Decl *caller);
   
   virtual void Profile(llvm::FoldingSetNodeID &ID) const;
 
index 4ada636e8e93c1ad41ff8d0c318af8c5bae129b3..995ef264eb4b31980473cead0ddfce8059f19672 100644 (file)
@@ -418,8 +418,10 @@ static void GenerateMinimalPathDiagnostic(PathDiagnostic& PD,
       assert(!PD.getActivePath().empty());
       PathDiagnosticCallPiece *C = 
         dyn_cast<PathDiagnosticCallPiece>(PD.getActivePath().front());
-      if (!C)
-        C = PathDiagnosticCallPiece::construct(PD.getActivePath());
+      if (!C) {
+        const Decl *Caller = CE->getLocationContext()->getDecl();
+        C = PathDiagnosticCallPiece::construct(PD.getActivePath(), Caller);
+      }
       C->setCallee(*CE, SMgr);
       continue;
     }
@@ -1064,8 +1066,10 @@ static void GenerateExtensivePathDiagnostic(PathDiagnostic& PD,
         // a new PathDiagnosticCallPiece.
         PathDiagnosticCallPiece *C =
           dyn_cast<PathDiagnosticCallPiece>(PD.getActivePath().front());
-        if (!C)
-          C = PathDiagnosticCallPiece::construct(PD.getActivePath());
+        if (!C) {
+          const Decl * Caller = CE->getLocationContext()->getDecl();
+          C = PathDiagnosticCallPiece::construct(PD.getActivePath(), Caller);
+        }
         C->setCallee(*CE, SM);
         EB.addContext(CE->getCallExpr());
         break;
index d09bb3280bbc71c6bbd1ff32ebe39277e6a8b031..ef815be0dbb218697184179dceb4f518c5136405 100644 (file)
@@ -515,8 +515,9 @@ PathDiagnosticCallPiece::construct(const ExplodedNode *N,
 }
 
 PathDiagnosticCallPiece *
-PathDiagnosticCallPiece::construct(PathPieces &path) {
-  PathDiagnosticCallPiece *C = new PathDiagnosticCallPiece(path);
+PathDiagnosticCallPiece::construct(PathPieces &path,
+                                   const Decl *caller) {
+  PathDiagnosticCallPiece *C = new PathDiagnosticCallPiece(path, caller);
   path.clear();
   path.push_front(C);
   return C;
@@ -563,7 +564,7 @@ PathDiagnosticCallPiece::getCallEnterWithinCallerEvent() const {
 
 IntrusiveRefCntPtr<PathDiagnosticEventPiece>
 PathDiagnosticCallPiece::getCallExitEvent() const {
-  if (!Caller)
+  if (NoExit)
     return 0;
   SmallString<256> buf;
   llvm::raw_svector_ostream Out(buf);
index 15b2070f239086fb887f0677ad5c63a6a1e338a5..852e93dff665a9f477aacfb19e25805f3df1eb0a 100644 (file)
@@ -281,7 +281,7 @@ void test_has_bug() {
 // CHECK:      </dict>
 // CHECK:      <key>depth</key><integer>1</integer>
 // CHECK:      <key>extended_message</key>
-// CHECK:      <string>Entered call
+// CHECK:      <string>Entered call from &apos;test_has_bug&apos;</string>
 // CHECK:      <key>message</key>
 // CHECK: <string>Entered call
 // CHECK:     </dict>