[cfe-commits] r152734 - in /cfe/trunk: include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h lib/StaticAnalyzer/Core/BugReporter.cpp lib/StaticAnalyzer/Core/PathDiagnostic.cpp test/Analysis/inline-plist.c

Anna Zaks ganna at apple.com
Wed Mar 14 11:58:28 PDT 2012


Author: zaks
Date: Wed Mar 14 13:58:28 2012
New Revision: 152734

URL: http://llvm.org/viewvc/llvm-project?rev=152734&view=rev
Log:
[analyzer] Diagnostics: Supply Caller information even if the bug occurs
in the callee.

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

Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h?rev=152734&r1=152733&r2=152734&view=diff
==============================================================================
--- cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h Wed Mar 14 13:58:28 2012
@@ -391,11 +391,17 @@
     : 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 @@
                                             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;
 

Modified: cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp?rev=152734&r1=152733&r2=152734&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp Wed Mar 14 13:58:28 2012
@@ -418,8 +418,10 @@
       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 @@
         // 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;

Modified: cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp?rev=152734&r1=152733&r2=152734&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp Wed Mar 14 13:58:28 2012
@@ -515,8 +515,9 @@
 }
 
 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 @@
 
 IntrusiveRefCntPtr<PathDiagnosticEventPiece>
 PathDiagnosticCallPiece::getCallExitEvent() const {
-  if (!Caller)
+  if (NoExit)
     return 0;
   SmallString<256> buf;
   llvm::raw_svector_ostream Out(buf);

Modified: cfe/trunk/test/Analysis/inline-plist.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/inline-plist.c?rev=152734&r1=152733&r2=152734&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/inline-plist.c (original)
+++ cfe/trunk/test/Analysis/inline-plist.c Wed Mar 14 13:58:28 2012
@@ -281,7 +281,7 @@
 // CHECK:      </dict>
 // CHECK:      <key>depth</key><integer>1</integer>
 // CHECK:      <key>extended_message</key>
-// CHECK:      <string>Entered call
+// CHECK:      <string>Entered call from 'test_has_bug'</string>
 // CHECK:      <key>message</key>
 // CHECK: <string>Entered call
 // CHECK:     </dict>





More information about the cfe-commits mailing list