summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorAnna Zaks <ganna@apple.com>2012-06-08 00:04:43 +0000
committerAnna Zaks <ganna@apple.com>2012-06-08 00:04:43 +0000
commitb60908db3a5fb06f7992420c8946e2eb49cb988a (patch)
tree543f6dcbce20225818b6f8d0a6e78d78248a477c /clang
parent93205d0d1222d174038da32366a739c8f1fefe51 (diff)
downloadbcm5719-llvm-b60908db3a5fb06f7992420c8946e2eb49cb988a.tar.gz
bcm5719-llvm-b60908db3a5fb06f7992420c8946e2eb49cb988a.zip
[analyzer] Add experimental "issue hash" to the plist diagnostic.
CmpRuns.py can be used to compare issues from different analyzer runs. Since it uses the issue line number to unique 2 issues, adding a new line to the beginning of a file makes all issues in the file reported as new. The hash will be an opaque value which could be used (along with the function name) by CmpRuns to identify the same issues. This way, we only fail to identify the same issue from two runs if the function it appears in changes (not perfect, but much better than nothing). llvm-svn: 158180
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp11
-rw-r--r--clang/test/Analysis/inline-plist.c6
-rw-r--r--clang/test/Analysis/malloc-plist.c15
-rw-r--r--clang/test/Analysis/plist-output-alternate.m7
-rw-r--r--clang/test/Analysis/plist-output.m9
5 files changed, 48 insertions, 0 deletions
diff --git a/clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp b/clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
index f1c620a018a..4156e4fb0cc 100644
--- a/clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
+++ b/clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
@@ -489,6 +489,17 @@ void PlistDiagnostics::FlushDiagnosticsImpl(
o << " <key>issue_context</key>";
EmitString(o, declName) << '\n';
}
+
+ // Output the bug hash for issue unique-ing. Currently, it's just an
+ // offset from the beginning of the function.
+ if (const Stmt *Body = DeclWithIssue->getBody()) {
+ FullSourceLoc Loc(SM->getExpansionLoc(D->getLocation().asLocation()),
+ *SM);
+ FullSourceLoc FunLoc(SM->getExpansionLoc(Body->getLocStart()), *SM);
+ o << " <key>issue_hash</key><integer>"
+ << Loc.getExpansionLineNumber() - FunLoc.getExpansionLineNumber()
+ << "</integer>\n";
+ }
}
}
diff --git a/clang/test/Analysis/inline-plist.c b/clang/test/Analysis/inline-plist.c
index 7f4822480f1..1523e82cc2e 100644
--- a/clang/test/Analysis/inline-plist.c
+++ b/clang/test/Analysis/inline-plist.c
@@ -274,6 +274,7 @@ void test_block_arg() {
// CHECK: <key>type</key><string>Division by zero</string>
// CHECK: <key>issue_context_kind</key><string>function</string>
// CHECK: <key>issue_context</key><string>foo</string>
+// CHECK: <key>issue_hash</key><integer>4</integer>
// CHECK: <key>location</key>
// CHECK: <dict>
// CHECK: <key>line</key><integer>14</integer>
@@ -396,6 +397,7 @@ void test_block_arg() {
// CHECK: <key>type</key><string>Dereference of null pointer</string>
// CHECK: <key>issue_context_kind</key><string>function</string>
// CHECK: <key>issue_context</key><string>has_bug</string>
+// CHECK: <key>issue_hash</key><integer>1</integer>
// CHECK: <key>location</key>
// CHECK: <dict>
// CHECK: <key>line</key><integer>19</integer>
@@ -649,6 +651,7 @@ void test_block_arg() {
// CHECK: <key>type</key><string>Dereference of null pointer</string>
// CHECK: <key>issue_context_kind</key><string>function</string>
// CHECK: <key>issue_context</key><string>triggers_bug</string>
+// CHECK: <key>issue_hash</key><integer>1</integer>
// CHECK: <key>location</key>
// CHECK: <dict>
// CHECK: <key>line</key><integer>27</integer>
@@ -945,6 +948,7 @@ void test_block_arg() {
// CHECK: <key>type</key><string>Dereference of null pointer</string>
// CHECK: <key>issue_context_kind</key><string>function</string>
// CHECK: <key>issue_context</key><string>test_block_ret</string>
+// CHECK: <key>issue_hash</key><integer>2</integer>
// CHECK: <key>location</key>
// CHECK: <dict>
// CHECK: <key>line</key><integer>51</integer>
@@ -1058,6 +1062,7 @@ void test_block_arg() {
// CHECK: <key>type</key><string>Dereference of null pointer</string>
// CHECK: <key>issue_context_kind</key><string>function</string>
// CHECK: <key>issue_context</key><string>test_block_blockvar</string>
+// CHECK: <key>issue_hash</key><integer>3</integer>
// CHECK: <key>location</key>
// CHECK: <dict>
// CHECK: <key>line</key><integer>57</integer>
@@ -1171,6 +1176,7 @@ void test_block_arg() {
// CHECK: <key>type</key><string>Dereference of null pointer</string>
// CHECK: <key>issue_context_kind</key><string>function</string>
// CHECK: <key>issue_context</key><string>test_block_arg</string>
+// CHECK: <key>issue_hash</key><integer>3</integer>
// CHECK: <key>location</key>
// CHECK: <dict>
// CHECK: <key>line</key><integer>63</integer>
diff --git a/clang/test/Analysis/malloc-plist.c b/clang/test/Analysis/malloc-plist.c
index ef401925437..11eef3e1400 100644
--- a/clang/test/Analysis/malloc-plist.c
+++ b/clang/test/Analysis/malloc-plist.c
@@ -364,6 +364,7 @@ void use_function_with_leak7() {
// CHECK: <key>type</key><string>Memory leak</string>
// CHECK: <key>issue_context_kind</key><string>function</string>
// CHECK: <key>issue_context</key><string>diagnosticTest</string>
+// CHECK: <key>issue_hash</key><integer>5</integer>
// CHECK: <key>location</key>
// CHECK: <dict>
// CHECK: <key>line</key><integer>14</integer>
@@ -525,6 +526,7 @@ void use_function_with_leak7() {
// CHECK: <key>type</key><string>Memory leak</string>
// CHECK: <key>issue_context_kind</key><string>function</string>
// CHECK: <key>issue_context</key><string>myArrayAllocation</string>
+// CHECK: <key>issue_hash</key><integer>4</integer>
// CHECK: <key>location</key>
// CHECK: <dict>
// CHECK: <key>line</key><integer>21</integer>
@@ -909,6 +911,7 @@ void use_function_with_leak7() {
// CHECK: <key>type</key><string>Memory leak</string>
// CHECK: <key>issue_context_kind</key><string>function</string>
// CHECK: <key>issue_context</key><string>reallocDiagnostics</string>
+// CHECK: <key>issue_hash</key><integer>5</integer>
// CHECK: <key>location</key>
// CHECK: <dict>
// CHECK: <key>line</key><integer>28</integer>
@@ -1307,6 +1310,7 @@ void use_function_with_leak7() {
// CHECK: <key>type</key><string>Memory leak</string>
// CHECK: <key>issue_context_kind</key><string>function</string>
// CHECK: <key>issue_context</key><string>test_wrapper</string>
+// CHECK: <key>issue_hash</key><integer>3</integer>
// CHECK: <key>location</key>
// CHECK: <dict>
// CHECK: <key>line</key><integer>45</integer>
@@ -1826,6 +1830,7 @@ void use_function_with_leak7() {
// CHECK: <key>type</key><string>Use-after-free</string>
// CHECK: <key>issue_context_kind</key><string>function</string>
// CHECK: <key>issue_context</key><string>test_double_action_call</string>
+// CHECK: <key>issue_hash</key><integer>3</integer>
// CHECK: <key>location</key>
// CHECK: <dict>
// CHECK: <key>line</key><integer>61</integer>
@@ -2384,6 +2389,7 @@ void use_function_with_leak7() {
// CHECK: <key>type</key><string>Memory leak</string>
// CHECK: <key>issue_context_kind</key><string>function</string>
// CHECK: <key>issue_context</key><string>reallocIntra</string>
+// CHECK: <key>issue_hash</key><integer>3</integer>
// CHECK: <key>location</key>
// CHECK: <dict>
// CHECK: <key>line</key><integer>76</integer>
@@ -2651,6 +2657,7 @@ void use_function_with_leak7() {
// CHECK: <key>type</key><string>Memory leak</string>
// CHECK: <key>issue_context_kind</key><string>function</string>
// CHECK: <key>issue_context</key><string>use_ret</string>
+// CHECK: <key>issue_hash</key><integer>3</integer>
// CHECK: <key>location</key>
// CHECK: <dict>
// CHECK: <key>line</key><integer>86</integer>
@@ -2812,6 +2819,7 @@ void use_function_with_leak7() {
// CHECK: <key>type</key><string>Memory leak</string>
// CHECK: <key>issue_context_kind</key><string>function</string>
// CHECK: <key>issue_context</key><string>LeakedSymbol</string>
+// CHECK: <key>issue_hash</key><integer>8</integer>
// CHECK: <key>location</key>
// CHECK: <dict>
// CHECK: <key>line</key><integer>97</integer>
@@ -3016,6 +3024,7 @@ void use_function_with_leak7() {
// CHECK: <key>type</key><string>Memory leak</string>
// CHECK: <key>issue_context_kind</key><string>function</string>
// CHECK: <key>issue_context</key><string>function_with_leak1</string>
+// CHECK: <key>issue_hash</key><integer>1</integer>
// CHECK: <key>location</key>
// CHECK: <dict>
// CHECK: <key>line</key><integer>102</integer>
@@ -3220,6 +3229,7 @@ void use_function_with_leak7() {
// CHECK: <key>type</key><string>Memory leak</string>
// CHECK: <key>issue_context_kind</key><string>function</string>
// CHECK: <key>issue_context</key><string>function_with_leak2</string>
+// CHECK: <key>issue_hash</key><integer>2</integer>
// CHECK: <key>location</key>
// CHECK: <dict>
// CHECK: <key>line</key><integer>111</integer>
@@ -3492,6 +3502,7 @@ void use_function_with_leak7() {
// CHECK: <key>type</key><string>Memory leak</string>
// CHECK: <key>issue_context_kind</key><string>function</string>
// CHECK: <key>issue_context</key><string>function_with_leak3</string>
+// CHECK: <key>issue_hash</key><integer>3</integer>
// CHECK: <key>location</key>
// CHECK: <dict>
// CHECK: <key>line</key><integer>120</integer>
@@ -3764,6 +3775,7 @@ void use_function_with_leak7() {
// CHECK: <key>type</key><string>Memory leak</string>
// CHECK: <key>issue_context_kind</key><string>function</string>
// CHECK: <key>issue_context</key><string>function_with_leak4</string>
+// CHECK: <key>issue_hash</key><integer>5</integer>
// CHECK: <key>location</key>
// CHECK: <dict>
// CHECK: <key>line</key><integer>131</integer>
@@ -3968,6 +3980,7 @@ void use_function_with_leak7() {
// CHECK: <key>type</key><string>Memory leak</string>
// CHECK: <key>issue_context_kind</key><string>function</string>
// CHECK: <key>issue_context</key><string>function_with_leak5</string>
+// CHECK: <key>issue_hash</key><integer>2</integer>
// CHECK: <key>location</key>
// CHECK: <dict>
// CHECK: <key>line</key><integer>142</integer>
@@ -4172,6 +4185,7 @@ void use_function_with_leak7() {
// CHECK: <key>type</key><string>Memory leak</string>
// CHECK: <key>issue_context_kind</key><string>function</string>
// CHECK: <key>issue_context</key><string>function_with_leak6</string>
+// CHECK: <key>issue_hash</key><integer>2</integer>
// CHECK: <key>location</key>
// CHECK: <dict>
// CHECK: <key>line</key><integer>153</integer>
@@ -4405,6 +4419,7 @@ void use_function_with_leak7() {
// CHECK: <key>type</key><string>Memory leak</string>
// CHECK: <key>issue_context_kind</key><string>function</string>
// CHECK: <key>issue_context</key><string>use_function_with_leak7</string>
+// CHECK: <key>issue_hash</key><integer>2</integer>
// CHECK: <key>location</key>
// CHECK: <dict>
// CHECK: <key>line</key><integer>169</integer>
diff --git a/clang/test/Analysis/plist-output-alternate.m b/clang/test/Analysis/plist-output-alternate.m
index 43f8340ab76..a338a79491f 100644
--- a/clang/test/Analysis/plist-output-alternate.m
+++ b/clang/test/Analysis/plist-output-alternate.m
@@ -137,6 +137,7 @@ void rdar8331641(int x) {
// CHECK: <key>type</key><string>Dereference of null pointer</string>
// CHECK: <key>issue_context_kind</key><string>function</string>
// CHECK: <key>issue_context</key><string>test_null_init</string>
+// CHECK: <key>issue_hash</key><integer>2</integer>
// CHECK: <key>location</key>
// CHECK: <dict>
// CHECK: <key>line</key><integer>6</integer>
@@ -216,6 +217,7 @@ void rdar8331641(int x) {
// CHECK: <key>type</key><string>Dereference of null pointer</string>
// CHECK: <key>issue_context_kind</key><string>function</string>
// CHECK: <key>issue_context</key><string>test_null_assign</string>
+// CHECK: <key>issue_hash</key><integer>3</integer>
// CHECK: <key>location</key>
// CHECK: <dict>
// CHECK: <key>line</key><integer>12</integer>
@@ -295,6 +297,7 @@ void rdar8331641(int x) {
// CHECK: <key>type</key><string>Dereference of null pointer</string>
// CHECK: <key>issue_context_kind</key><string>function</string>
// CHECK: <key>issue_context</key><string>test_null_assign_transitive</string>
+// CHECK: <key>issue_hash</key><integer>4</integer>
// CHECK: <key>location</key>
// CHECK: <dict>
// CHECK: <key>line</key><integer>19</integer>
@@ -437,6 +440,7 @@ void rdar8331641(int x) {
// CHECK: <key>type</key><string>Dereference of null pointer</string>
// CHECK: <key>issue_context_kind</key><string>function</string>
// CHECK: <key>issue_context</key><string>test_null_cond</string>
+// CHECK: <key>issue_hash</key><integer>2</integer>
// CHECK: <key>location</key>
// CHECK: <dict>
// CHECK: <key>line</key><integer>24</integer>
@@ -584,6 +588,7 @@ void rdar8331641(int x) {
// CHECK: <key>type</key><string>Dereference of null pointer</string>
// CHECK: <key>issue_context_kind</key><string>function</string>
// CHECK: <key>issue_context</key><string>test_null_cond_transitive</string>
+// CHECK: <key>issue_hash</key><integer>3</integer>
// CHECK: <key>location</key>
// CHECK: <dict>
// CHECK: <key>line</key><integer>31</integer>
@@ -697,6 +702,7 @@ void rdar8331641(int x) {
// CHECK: <key>type</key><string>Dereference of null pointer</string>
// CHECK: <key>issue_context_kind</key><string>function</string>
// CHECK: <key>issue_context</key><string>test_null_field</string>
+// CHECK: <key>issue_hash</key><integer>3</integer>
// CHECK: <key>location</key>
// CHECK: <dict>
// CHECK: <key>line</key><integer>38</integer>
@@ -960,6 +966,7 @@ void rdar8331641(int x) {
// CHECK: <key>type</key><string>Leak</string>
// CHECK: <key>issue_context_kind</key><string>function</string>
// CHECK: <key>issue_context</key><string>rdar8331641</string>
+// CHECK: <key>issue_hash</key><integer>6</integer>
// CHECK: <key>location</key>
// CHECK: <dict>
// CHECK: <key>line</key><integer>58</integer>
diff --git a/clang/test/Analysis/plist-output.m b/clang/test/Analysis/plist-output.m
index 3d04cbfe465..cae08abe5f5 100644
--- a/clang/test/Analysis/plist-output.m
+++ b/clang/test/Analysis/plist-output.m
@@ -160,6 +160,7 @@ int test_cond_assign() {
// CHECK: <key>type</key><string>Dereference of null pointer</string>
// CHECK: <key>issue_context_kind</key><string>function</string>
// CHECK: <key>issue_context</key><string>test_null_init</string>
+// CHECK: <key>issue_hash</key><integer>2</integer>
// CHECK: <key>location</key>
// CHECK: <dict>
// CHECK: <key>line</key><integer>6</integer>
@@ -239,6 +240,7 @@ int test_cond_assign() {
// CHECK: <key>type</key><string>Dereference of null pointer</string>
// CHECK: <key>issue_context_kind</key><string>function</string>
// CHECK: <key>issue_context</key><string>test_null_assign</string>
+// CHECK: <key>issue_hash</key><integer>3</integer>
// CHECK: <key>location</key>
// CHECK: <dict>
// CHECK: <key>line</key><integer>12</integer>
@@ -318,6 +320,7 @@ int test_cond_assign() {
// CHECK: <key>type</key><string>Dereference of null pointer</string>
// CHECK: <key>issue_context_kind</key><string>function</string>
// CHECK: <key>issue_context</key><string>test_null_assign_transitive</string>
+// CHECK: <key>issue_hash</key><integer>4</integer>
// CHECK: <key>location</key>
// CHECK: <dict>
// CHECK: <key>line</key><integer>19</integer>
@@ -460,6 +463,7 @@ int test_cond_assign() {
// CHECK: <key>type</key><string>Dereference of null pointer</string>
// CHECK: <key>issue_context_kind</key><string>function</string>
// CHECK: <key>issue_context</key><string>test_null_cond</string>
+// CHECK: <key>issue_hash</key><integer>2</integer>
// CHECK: <key>location</key>
// CHECK: <dict>
// CHECK: <key>line</key><integer>24</integer>
@@ -607,6 +611,7 @@ int test_cond_assign() {
// CHECK: <key>type</key><string>Dereference of null pointer</string>
// CHECK: <key>issue_context_kind</key><string>function</string>
// CHECK: <key>issue_context</key><string>test_null_cond_transitive</string>
+// CHECK: <key>issue_hash</key><integer>4</integer>
// CHECK: <key>location</key>
// CHECK: <dict>
// CHECK: <key>line</key><integer>32</integer>
@@ -720,6 +725,7 @@ int test_cond_assign() {
// CHECK: <key>type</key><string>Dereference of null pointer</string>
// CHECK: <key>issue_context_kind</key><string>function</string>
// CHECK: <key>issue_context</key><string>test_null_field</string>
+// CHECK: <key>issue_hash</key><integer>3</integer>
// CHECK: <key>location</key>
// CHECK: <dict>
// CHECK: <key>line</key><integer>39</integer>
@@ -935,6 +941,7 @@ int test_cond_assign() {
// CHECK: <key>type</key><string>Dereference of null pointer</string>
// CHECK: <key>issue_context_kind</key><string>function</string>
// CHECK: <key>issue_context</key><string>test_assumptions</string>
+// CHECK: <key>issue_hash</key><integer>8</integer>
// CHECK: <key>location</key>
// CHECK: <dict>
// CHECK: <key>line</key><integer>51</integer>
@@ -1145,6 +1152,7 @@ int test_cond_assign() {
// CHECK: <key>type</key><string>Dereference of null pointer</string>
// CHECK: <key>issue_context_kind</key><string>function</string>
// CHECK: <key>issue_context</key><string>test_cond_assign</string>
+// CHECK: <key>issue_hash</key><integer>4</integer>
// CHECK: <key>location</key>
// CHECK: <dict>
// CHECK: <key>line</key><integer>59</integer>
@@ -1326,6 +1334,7 @@ int test_cond_assign() {
// CHECK: <key>type</key><string>Dereference of null pointer</string>
// CHECK: <key>issue_context_kind</key><string>Objective-C method</string>
// CHECK: <key>issue_context</key><string>test</string>
+// CHECK: <key>issue_hash</key><integer>3</integer>
// CHECK: <key>location</key>
// CHECK: <dict>
// CHECK: <key>line</key><integer>78</integer>
OpenPOWER on IntegriCloud