diff options
author | Artem Dergachev <artem.dergachev@gmail.com> | 2019-09-06 20:55:29 +0000 |
---|---|---|
committer | Artem Dergachev <artem.dergachev@gmail.com> | 2019-09-06 20:55:29 +0000 |
commit | 6cee434ed10ead6b7416ca5ee9592b2b207eeb0f (patch) | |
tree | 8af15b8d39c1d88aff40f5bef27e77279f787ba7 /clang/test/Analysis | |
parent | 2b1b4cab9605a33a6c90079b44bdddf048104e08 (diff) | |
download | bcm5719-llvm-6cee434ed10ead6b7416ca5ee9592b2b207eeb0f.tar.gz bcm5719-llvm-6cee434ed10ead6b7416ca5ee9592b2b207eeb0f.zip |
[analyzer] Add minimal support for fix-it hints.
Allow attaching fixit hints to Static Analyzer BugReports.
Fixits are attached either to the bug report itself or to its notes
(path-sensitive event notes or path-insensitive extra notes).
Add support for fixits in text output (including the default text output that
goes without notes, as long as the fixit "belongs" to the warning).
Add support for fixits in the plist output mode.
Implement a fixit for the path-insensitive DeadStores checker. Only dead
initialization warning is currently covered.
Implement a fixit for the path-sensitive VirtualCall checker when the virtual
method is not pure virtual (in this case the "fix" is to suppress the warning
by qualifying the call).
Both fixits are under an off-by-default flag for now, because they
require more careful testing.
Differential Revision: https://reviews.llvm.org/D65182
llvm-svn: 371257
Diffstat (limited to 'clang/test/Analysis')
-rw-r--r-- | clang/test/Analysis/analyzer-config.c | 5 | ||||
-rw-r--r-- | clang/test/Analysis/dead-stores.c | 32 | ||||
-rw-r--r-- | clang/test/Analysis/edges-new.mm | 2 | ||||
-rw-r--r-- | clang/test/Analysis/objc-arc.m | 2 | ||||
-rw-r--r-- | clang/test/Analysis/plist-output.m | 2 | ||||
-rw-r--r-- | clang/test/Analysis/virtualcall-fixits.cpp | 45 |
6 files changed, 70 insertions, 18 deletions
diff --git a/clang/test/Analysis/analyzer-config.c b/clang/test/Analysis/analyzer-config.c index c8a24eea501..6c6883d88d6 100644 --- a/clang/test/Analysis/analyzer-config.c +++ b/clang/test/Analysis/analyzer-config.c @@ -30,6 +30,7 @@ // CHECK-NEXT: ctu-dir = "" // CHECK-NEXT: ctu-import-threshold = 100 // CHECK-NEXT: ctu-index-name = externalDefMap.txt +// CHECK-NEXT: deadcode.DeadStores:ShowFixIts = false // CHECK-NEXT: deadcode.DeadStores:WarnForDeadNestedAssignments = true // CHECK-NEXT: debug.AnalysisOrder:* = false // CHECK-NEXT: debug.AnalysisOrder:Bind = false @@ -54,6 +55,7 @@ // CHECK-NEXT: experimental-enable-naive-ctu-analysis = false // CHECK-NEXT: exploration_strategy = unexplored_first_queue // CHECK-NEXT: faux-bodies = true +// CHECK-NEXT: fixits-as-remarks = false // CHECK-NEXT: graph-trim-interval = 1000 // CHECK-NEXT: inline-lambdas = true // CHECK-NEXT: ipa = dynamic-bifurcate @@ -74,6 +76,7 @@ // CHECK-NEXT: optin.cplusplus.UninitializedObject:NotesAsWarnings = false // CHECK-NEXT: optin.cplusplus.UninitializedObject:Pedantic = false // CHECK-NEXT: optin.cplusplus.VirtualCall:PureOnly = false +// CHECK-NEXT: optin.cplusplus.VirtualCall:ShowFixIts = false // CHECK-NEXT: optin.osx.cocoa.localizability.NonLocalizedStringChecker:AggressiveReport = false // CHECK-NEXT: optin.performance.Padding:AllowedPad = 24 // CHECK-NEXT: osx.NumberObjectConversion:Pedantic = false @@ -94,4 +97,4 @@ // CHECK-NEXT: unroll-loops = false // CHECK-NEXT: widen-loops = false // CHECK-NEXT: [stats] -// CHECK-NEXT: num-entries = 91 +// CHECK-NEXT: num-entries = 94 diff --git a/clang/test/Analysis/dead-stores.c b/clang/test/Analysis/dead-stores.c index 26377f7617e..cbfdabdcec6 100644 --- a/clang/test/Analysis/dead-stores.c +++ b/clang/test/Analysis/dead-stores.c @@ -1,17 +1,16 @@ -// RUN: %clang_analyze_cc1 -Wunused-variable -fblocks -Wno-unreachable-code \ -// RUN: -analyzer-checker=core,deadcode.DeadStores \ -// RUN: -analyzer-config deadcode.DeadStores:WarnForDeadNestedAssignments=false\ -// RUN: -analyzer-opt-analyze-nested-blocks -verify=non-nested %s -// -// RUN: %clang_analyze_cc1 -Wunused-variable -fblocks -Wno-unreachable-code \ -// RUN: -analyzer-checker=core,deadcode.DeadStores \ -// RUN: -analyzer-config deadcode.DeadStores:WarnForDeadNestedAssignments=false\ -// RUN: -analyzer-opt-analyze-nested-blocks -verify=non-nested \ -// RUN: -analyzer-store=region %s -// -// RUN: %clang_analyze_cc1 -Wunused-variable -fblocks -Wno-unreachable-code \ -// RUN: -analyzer-checker=core,deadcode.DeadStores \ -// RUN: -analyzer-opt-analyze-nested-blocks -verify=non-nested,nested %s +// RUN: %clang_analyze_cc1 -Wunused-variable -fblocks -Wno-unreachable-code \ +// RUN: -analyzer-checker=core,deadcode.DeadStores \ +// RUN: -analyzer-config deadcode.DeadStores:ShowFixIts=true \ +// RUN: -analyzer-config fixits-as-remarks=true \ +// RUN: -analyzer-config \ +// RUN: deadcode.DeadStores:WarnForDeadNestedAssignments=false \ +// RUN: -verify=non-nested %s + +// RUN: %clang_analyze_cc1 -Wunused-variable -fblocks -Wno-unreachable-code \ +// RUN: -analyzer-checker=core,deadcode.DeadStores \ +// RUN: -analyzer-config deadcode.DeadStores:ShowFixIts=true \ +// RUN: -analyzer-config fixits-as-remarks=true \ +// RUN: -verify=non-nested,nested %s void f1() { int k, y; // non-nested-warning {{unused variable 'k'}} @@ -19,12 +18,14 @@ void f1() { int abc = 1; long idx = abc + 3 * 5; // non-nested-warning {{never read}} // non-nested-warning@-1 {{unused variable 'idx'}} + // non-nested-remark@-2 {{11-24: ''}} } void f2(void *b) { char *c = (char *)b; // no-warning char *d = b + 1; // non-nested-warning {{never read}} // non-nested-warning@-1 {{unused variable 'd'}} + // non-nested-remark@-2 {{10-17: ''}} printf("%s", c); // non-nested-warning@-1 {{implicitly declaring library function 'printf' with type 'int (const char *, ...)'}} // non-nested-note@-2 {{include the header <stdio.h> or explicitly provide a declaration for 'printf'}} @@ -50,6 +51,7 @@ void f5() { int x = 4; // no-warning int *p = &x; // non-nested-warning {{never read}} // non-nested-warning@-1 {{unused variable 'p'}} + // non-nested-remark@-2 {{9-13: ''}} } int f6() { @@ -413,6 +415,7 @@ void f23_pos(int argc, char **argv) { int shouldLog = (argc > 1); // non-nested-warning@-1 {{Value stored to 'shouldLog' during its initialization is never read}} // non-nested-warning@-2 {{unused variable 'shouldLog'}} + // non-nested-remark@-3 {{16-28: ''}} ^{ f23_aux("I did too use it!\n"); }(); @@ -425,6 +428,7 @@ void f24_A(int y) { int z = x + y; // non-nested-warning@-1 {{Value stored to 'z' during its initialization is never read}} // non-nested-warning@-2 {{unused variable 'z'}} + // non-nested-remark@-3 {{10-17: ''}} }(); } diff --git a/clang/test/Analysis/edges-new.mm b/clang/test/Analysis/edges-new.mm index dda1bfb31e7..6bddbef58f1 100644 --- a/clang/test/Analysis/edges-new.mm +++ b/clang/test/Analysis/edges-new.mm @@ -1,4 +1,4 @@ -// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -analyzer-checker=core,deadcode.DeadStores,osx.cocoa.RetainCount,unix.Malloc,unix.MismatchedDeallocator -analyzer-output=plist -o %t -w %s +// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -analyzer-checker=core,deadcode.DeadStores,osx.cocoa.RetainCount,unix.Malloc,unix.MismatchedDeallocator -analyzer-output=plist -analyzer-config deadcode.DeadStores:ShowFixIts=true -o %t -w %s // RUN: %normalize_plist <%t | diff -ub %S/Inputs/expected-plists/edges-new.mm.plist - //===----------------------------------------------------------------------===// diff --git a/clang/test/Analysis/objc-arc.m b/clang/test/Analysis/objc-arc.m index cab6618a436..7127232f0de 100644 --- a/clang/test/Analysis/objc-arc.m +++ b/clang/test/Analysis/objc-arc.m @@ -1,4 +1,4 @@ -// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -analyzer-checker=core,osx.cocoa.RetainCount,deadcode -verify -fblocks -analyzer-opt-analyze-nested-blocks -fobjc-arc -analyzer-output=plist-multi-file -o %t.plist %s +// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -analyzer-checker=core,osx.cocoa.RetainCount,deadcode -verify -fblocks -analyzer-opt-analyze-nested-blocks -fobjc-arc -analyzer-output=plist-multi-file -analyzer-config deadcode.DeadStores:ShowFixIts=true -o %t.plist %s // RUN: %normalize_plist <%t.plist | diff -ub %S/Inputs/expected-plists/objc-arc.m.plist - typedef signed char BOOL; diff --git a/clang/test/Analysis/plist-output.m b/clang/test/Analysis/plist-output.m index 32916333cbf..553982b32fd 100644 --- a/clang/test/Analysis/plist-output.m +++ b/clang/test/Analysis/plist-output.m @@ -1,4 +1,4 @@ -// RUN: %clang_analyze_cc1 -analyzer-config eagerly-assume=false %s -analyzer-checker=osx.cocoa.RetainCount,deadcode.DeadStores,core -analyzer-output=plist -o %t.plist +// RUN: %clang_analyze_cc1 -analyzer-config eagerly-assume=false %s -analyzer-checker=osx.cocoa.RetainCount,deadcode.DeadStores,core -analyzer-output=plist -analyzer-config deadcode.DeadStores:ShowFixIts=true -o %t.plist // RUN: %normalize_plist <%t.plist | diff -ub %S/Inputs/expected-plists/plist-output.m.plist - void test_null_init(void) { diff --git a/clang/test/Analysis/virtualcall-fixits.cpp b/clang/test/Analysis/virtualcall-fixits.cpp new file mode 100644 index 00000000000..ea149d52fcd --- /dev/null +++ b/clang/test/Analysis/virtualcall-fixits.cpp @@ -0,0 +1,45 @@ +// RUN: %clang_analyze_cc1 -analyzer-checker=core,optin.cplusplus.VirtualCall \ +// RUN: -analyzer-config optin.cplusplus.VirtualCall:ShowFixIts=true \ +// RUN: %s 2>&1 | FileCheck -check-prefix=TEXT %s +// RUN: %clang_analyze_cc1 -analyzer-checker=core,optin.cplusplus.VirtualCall \ +// RUN: -analyzer-config optin.cplusplus.VirtualCall:ShowFixIts=true \ +// RUN: -analyzer-config fixits-as-remarks=true \ +// RUN: -analyzer-output=plist -o %t.plist -verify %s +// RUN: cat %t.plist | FileCheck -check-prefix=PLIST %s + +struct S { + virtual void foo(); + S() { + foo(); + // expected-warning@-1{{Call to virtual method 'S::foo' during construction bypasses virtual dispatch}} + // expected-remark@-2{{5-5: 'S::'}} + } + ~S(); +}; + +// TEXT: warning: Call to virtual method 'S::foo' during construction +// TEXT-SAME: bypasses virtual dispatch +// TEXT-NEXT: foo(); +// TEXT-NEXT: ^~~~~ +// TEXT-NEXT: S:: +// TEXT-NEXT: 1 warning generated. + +// PLIST: <key>fixits</key> +// PLIST-NEXT: <array> +// PLIST-NEXT: <dict> +// PLIST-NEXT: <key>remove_range</key> +// PLIST-NEXT: <array> +// PLIST-NEXT: <dict> +// PLIST-NEXT: <key>line</key><integer>13</integer> +// PLIST-NEXT: <key>col</key><integer>5</integer> +// PLIST-NEXT: <key>file</key><integer>0</integer> +// PLIST-NEXT: </dict> +// PLIST-NEXT: <dict> +// PLIST-NEXT: <key>line</key><integer>13</integer> +// PLIST-NEXT: <key>col</key><integer>4</integer> +// PLIST-NEXT: <key>file</key><integer>0</integer> +// PLIST-NEXT: </dict> +// PLIST-NEXT: </array> +// PLIST-NEXT: <key>insert_string</key><string>S::</string> +// PLIST-NEXT: </dict> +// PLIST-NEXT: </array> |