[cfe-commits] r157950 - in /cfe/trunk: lib/StaticAnalyzer/Core/PlistDiagnostics.cpp test/Analysis/diagnostics/ test/Analysis/diagnostics/undef-value-callee.h test/Analysis/diagnostics/undef-value-caller.c

Anna Zaks ganna at apple.com
Mon Jun 4 14:03:31 PDT 2012


Author: zaks
Date: Mon Jun  4 16:03:31 2012
New Revision: 157950

URL: http://llvm.org/viewvc/llvm-project?rev=157950&view=rev
Log:
[analyzer] Fix a diagnostics bug which lead to a crash on the buildbot.

This bug was triggered by r157851. It only happens in the case where we
don't perform optimal diagnostic pruning.

Added:
    cfe/trunk/test/Analysis/diagnostics/
    cfe/trunk/test/Analysis/diagnostics/undef-value-callee.h
    cfe/trunk/test/Analysis/diagnostics/undef-value-caller.c
Modified:
    cfe/trunk/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp?rev=157950&r1=157949&r2=157950&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp Mon Jun  4 16:03:31 2012
@@ -382,6 +382,11 @@
 
         if (const PathDiagnosticCallPiece *call =
             dyn_cast<PathDiagnosticCallPiece>(piece)) {
+          IntrusiveRefCntPtr<PathDiagnosticEventPiece>
+            callEnterWithin = call->getCallEnterWithinCallerEvent();
+          if (callEnterWithin)
+            AddFID(FM, Fids, SM, callEnterWithin->getLocation().asLocation());
+
           WorkList.push_back(&call->path);
         }
         else if (const PathDiagnosticMacroPiece *macro =

Added: cfe/trunk/test/Analysis/diagnostics/undef-value-callee.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/diagnostics/undef-value-callee.h?rev=157950&view=auto
==============================================================================
--- cfe/trunk/test/Analysis/diagnostics/undef-value-callee.h (added)
+++ cfe/trunk/test/Analysis/diagnostics/undef-value-callee.h Mon Jun  4 16:03:31 2012
@@ -0,0 +1,4 @@
+
+void callee() {
+  ;
+}

Added: cfe/trunk/test/Analysis/diagnostics/undef-value-caller.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/diagnostics/undef-value-caller.c?rev=157950&view=auto
==============================================================================
--- cfe/trunk/test/Analysis/diagnostics/undef-value-caller.c (added)
+++ cfe/trunk/test/Analysis/diagnostics/undef-value-caller.c Mon Jun  4 16:03:31 2012
@@ -0,0 +1,237 @@
+// RUN: %clang_cc1 -analyze -analyzer-checker=core -analyzer-output=plist -o %t %s
+// RUN: FileCheck --input-file %t %s
+
+#include "undef-value-callee.h"
+
+// This code used to cause a crash since we were not adding fileID of the header to the plist diagnostic.
+// Note, in the future, we do not even need to step into this callee since it does not influence the result.
+int test_calling_unimportant_callee(int argc, char *argv[]) {
+  int x;
+  callee();
+  return x; // expected-warning {{Undefined or garbage value returned to caller}}
+}
+//CHECK:  <dict>
+//CHECK:   <key>files</key>
+//CHECK:   <array>
+//CHECK:    <string>/Users/anya/workspace/gllvm/llvm/tools/clang/test/Analysis/diagnostics/undef-value-caller.c</string>
+//CHECK:    <string>/Users/anya/workspace/gllvm/llvm/tools/clang/test/Analysis/diagnostics/undef-value-callee.h</string>
+//CHECK:   </array>
+//CHECK:   <key>diagnostics</key>
+//CHECK:   <array>
+//CHECK:    <dict>
+//CHECK:     <key>path</key>
+//CHECK:     <array>
+//CHECK:      <dict>
+//CHECK:       <key>kind</key><string>event</string>
+//CHECK:       <key>location</key>
+//CHECK:       <dict>
+//CHECK:        <key>line</key><integer>9</integer>
+//CHECK:        <key>col</key><integer>3</integer>
+//CHECK:        <key>file</key><integer>0</integer>
+//CHECK:       </dict>
+//CHECK:       <key>ranges</key>
+//CHECK:       <array>
+//CHECK:         <array>
+//CHECK:          <dict>
+//CHECK:           <key>line</key><integer>9</integer>
+//CHECK:           <key>col</key><integer>3</integer>
+//CHECK:           <key>file</key><integer>0</integer>
+//CHECK:          </dict>
+//CHECK:          <dict>
+//CHECK:           <key>line</key><integer>9</integer>
+//CHECK:           <key>col</key><integer>7</integer>
+//CHECK:           <key>file</key><integer>0</integer>
+//CHECK:          </dict>
+//CHECK:         </array>
+//CHECK:       </array>
+//CHECK:       <key>depth</key><integer>0</integer>
+//CHECK:       <key>extended_message</key>
+//CHECK:       <string>Variable 'x' declared without an initial value</string>
+//CHECK:       <key>message</key>
+//CHECK:  <string>Variable 'x' declared without an initial value</string>
+//CHECK:      </dict>
+//CHECK:      <dict>
+//CHECK:       <key>kind</key><string>control</string>
+//CHECK:       <key>edges</key>
+//CHECK:        <array>
+//CHECK:         <dict>
+//CHECK:          <key>start</key>
+//CHECK:           <array>
+//CHECK:            <dict>
+//CHECK:             <key>line</key><integer>9</integer>
+//CHECK:             <key>col</key><integer>3</integer>
+//CHECK:             <key>file</key><integer>0</integer>
+//CHECK:            </dict>
+//CHECK:            <dict>
+//CHECK:             <key>line</key><integer>9</integer>
+//CHECK:             <key>col</key><integer>7</integer>
+//CHECK:             <key>file</key><integer>0</integer>
+//CHECK:            </dict>
+//CHECK:           </array>
+//CHECK:          <key>end</key>
+//CHECK:           <array>
+//CHECK:            <dict>
+//CHECK:             <key>line</key><integer>10</integer>
+//CHECK:             <key>col</key><integer>3</integer>
+//CHECK:             <key>file</key><integer>0</integer>
+//CHECK:            </dict>
+//CHECK:            <dict>
+//CHECK:             <key>line</key><integer>10</integer>
+//CHECK:             <key>col</key><integer>3</integer>
+//CHECK:             <key>file</key><integer>0</integer>
+//CHECK:            </dict>
+//CHECK:           </array>
+//CHECK:         </dict>
+//CHECK:        </array>
+//CHECK:      </dict>
+//CHECK:      <dict>
+//CHECK:       <key>kind</key><string>event</string>
+//CHECK:       <key>location</key>
+//CHECK:       <dict>
+//CHECK:        <key>line</key><integer>10</integer>
+//CHECK:        <key>col</key><integer>3</integer>
+//CHECK:        <key>file</key><integer>0</integer>
+//CHECK:       </dict>
+//CHECK:       <key>ranges</key>
+//CHECK:       <array>
+//CHECK:         <array>
+//CHECK:          <dict>
+//CHECK:           <key>line</key><integer>10</integer>
+//CHECK:           <key>col</key><integer>3</integer>
+//CHECK:           <key>file</key><integer>0</integer>
+//CHECK:          </dict>
+//CHECK:          <dict>
+//CHECK:           <key>line</key><integer>10</integer>
+//CHECK:           <key>col</key><integer>10</integer>
+//CHECK:           <key>file</key><integer>0</integer>
+//CHECK:          </dict>
+//CHECK:         </array>
+//CHECK:       </array>
+//CHECK:       <key>depth</key><integer>0</integer>
+//CHECK:       <key>extended_message</key>
+//CHECK:       <string>Calling 'callee'</string>
+//CHECK:       <key>message</key>
+//CHECK:  <string>Calling 'callee'</string>
+//CHECK:      </dict>
+//CHECK:      <dict>
+//CHECK:       <key>kind</key><string>event</string>
+//CHECK:       <key>location</key>
+//CHECK:       <dict>
+//CHECK:        <key>line</key><integer>2</integer>
+//CHECK:        <key>col</key><integer>1</integer>
+//CHECK:        <key>file</key><integer>1</integer>
+//CHECK:       </dict>
+//CHECK:       <key>depth</key><integer>1</integer>
+//CHECK:       <key>extended_message</key>
+//CHECK:       <string>Entered call from 'test_calling_unimportant_callee'</string>
+//CHECK:       <key>message</key>
+//CHECK:  <string>Entered call from 'test_calling_unimportant_callee'</string>
+//CHECK:      </dict>
+//CHECK:      <dict>
+//CHECK:       <key>kind</key><string>event</string>
+//CHECK:       <key>location</key>
+//CHECK:       <dict>
+//CHECK:        <key>line</key><integer>10</integer>
+//CHECK:        <key>col</key><integer>3</integer>
+//CHECK:        <key>file</key><integer>0</integer>
+//CHECK:       </dict>
+//CHECK:       <key>ranges</key>
+//CHECK:       <array>
+//CHECK:         <array>
+//CHECK:          <dict>
+//CHECK:           <key>line</key><integer>10</integer>
+//CHECK:           <key>col</key><integer>3</integer>
+//CHECK:           <key>file</key><integer>0</integer>
+//CHECK:          </dict>
+//CHECK:          <dict>
+//CHECK:           <key>line</key><integer>10</integer>
+//CHECK:           <key>col</key><integer>10</integer>
+//CHECK:           <key>file</key><integer>0</integer>
+//CHECK:          </dict>
+//CHECK:         </array>
+//CHECK:       </array>
+//CHECK:       <key>depth</key><integer>1</integer>
+//CHECK:       <key>extended_message</key>
+//CHECK:       <string>Returning from 'callee'</string>
+//CHECK:       <key>message</key>
+//CHECK:  <string>Returning from 'callee'</string>
+//CHECK:      </dict>
+//CHECK:      <dict>
+//CHECK:       <key>kind</key><string>control</string>
+//CHECK:       <key>edges</key>
+//CHECK:        <array>
+//CHECK:         <dict>
+//CHECK:          <key>start</key>
+//CHECK:           <array>
+//CHECK:            <dict>
+//CHECK:             <key>line</key><integer>10</integer>
+//CHECK:             <key>col</key><integer>3</integer>
+//CHECK:             <key>file</key><integer>0</integer>
+//CHECK:            </dict>
+//CHECK:            <dict>
+//CHECK:             <key>line</key><integer>10</integer>
+//CHECK:             <key>col</key><integer>10</integer>
+//CHECK:             <key>file</key><integer>0</integer>
+//CHECK:            </dict>
+//CHECK:           </array>
+//CHECK:          <key>end</key>
+//CHECK:           <array>
+//CHECK:            <dict>
+//CHECK:             <key>line</key><integer>11</integer>
+//CHECK:             <key>col</key><integer>3</integer>
+//CHECK:             <key>file</key><integer>0</integer>
+//CHECK:            </dict>
+//CHECK:            <dict>
+//CHECK:             <key>line</key><integer>11</integer>
+//CHECK:             <key>col</key><integer>10</integer>
+//CHECK:             <key>file</key><integer>0</integer>
+//CHECK:            </dict>
+//CHECK:           </array>
+//CHECK:         </dict>
+//CHECK:        </array>
+//CHECK:      </dict>
+//CHECK:      <dict>
+//CHECK:       <key>kind</key><string>event</string>
+//CHECK:       <key>location</key>
+//CHECK:       <dict>
+//CHECK:        <key>line</key><integer>11</integer>
+//CHECK:        <key>col</key><integer>3</integer>
+//CHECK:        <key>file</key><integer>0</integer>
+//CHECK:       </dict>
+//CHECK:       <key>ranges</key>
+//CHECK:       <array>
+//CHECK:         <array>
+//CHECK:          <dict>
+//CHECK:           <key>line</key><integer>11</integer>
+//CHECK:           <key>col</key><integer>10</integer>
+//CHECK:           <key>file</key><integer>0</integer>
+//CHECK:          </dict>
+//CHECK:          <dict>
+//CHECK:           <key>line</key><integer>11</integer>
+//CHECK:           <key>col</key><integer>10</integer>
+//CHECK:           <key>file</key><integer>0</integer>
+//CHECK:          </dict>
+//CHECK:         </array>
+//CHECK:       </array>
+//CHECK:       <key>depth</key><integer>0</integer>
+//CHECK:       <key>extended_message</key>
+//CHECK:       <string>Undefined or garbage value returned to caller</string>
+//CHECK:       <key>message</key>
+//CHECK:  <string>Undefined or garbage value returned to caller</string>
+//CHECK:      </dict>
+//CHECK:     </array>
+//CHECK:     <key>description</key><string>Undefined or garbage value returned to caller</string>
+//CHECK:     <key>category</key><string>Logic error</string>
+//CHECK:     <key>type</key><string>Garbage return value</string>
+//CHECK:    <key>issue_context_kind</key><string>function</string>
+//CHECK:    <key>issue_context</key><string>test_calling_unimportant_callee</string>
+//CHECK:    <key>location</key>
+//CHECK:    <dict>
+//CHECK:     <key>line</key><integer>11</integer>
+//CHECK:     <key>col</key><integer>3</integer>
+//CHECK:     <key>file</key><integer>0</integer>
+//CHECK:    </dict>
+//CHECK:    </dict>
+//CHECK:   </array>
+//CHECK:  </dict>
+//CHECK:  </plist>





More information about the cfe-commits mailing list