75 lines · cpp
1// RUN: %clang_analyze_cc1 -verify=common %s \2// RUN: -analyzer-checker=deadcode.DeadStores,debug.ExprInspection \3// RUN: -analyzer-note-analysis-entry-points4 5// RUN: %clang_analyze_cc1 -verify=common,textout %s \6// RUN: -analyzer-checker=deadcode.DeadStores,debug.ExprInspection \7// RUN: -analyzer-note-analysis-entry-points \8// RUN: -analyzer-output=text9 10// Test the actual source locations/ranges of entry point notes.11// RUN: %clang_analyze_cc1 %s \12// RUN: -analyzer-checker=deadcode.DeadStores,debug.ExprInspection \13// RUN: -analyzer-note-analysis-entry-points \14// RUN: -analyzer-output=text 2>&1 \15// RUN: | FileCheck --strict-whitespace %s16 17 18void clang_analyzer_warnIfReached();19 20void other() {21 // common-warning@+1 {{REACHABLE}} textout-note@+1 {{REACHABLE}}22 clang_analyzer_warnIfReached();23}24 25struct SomeOtherStruct {26 // CHECK: note: [debug] analyzing from SomeOtherStruct::f()27 // CHECK-NEXT: | void f() {28 // CHECK-NEXT: | ^29 // textout-note@+1 {{[debug] analyzing from SomeOtherStruct::f()}}30 void f() {31 other(); // textout-note {{Calling 'other'}}32 }33};34 35// CHECK: note: [debug] analyzing from operator""_w(const char *)36// CHECK-NEXT: | unsigned operator ""_w(const char*) {37// CHECK-NEXT: | ^38// textout-note@+1 {{[debug] analyzing from operator""_w(const char *)}}39unsigned operator ""_w(const char*) {40 // common-warning@+1 {{REACHABLE}} textout-note@+1 {{REACHABLE}}41 clang_analyzer_warnIfReached();42 return 404;43}44 45// textout-note@+1 {{[debug] analyzing from checkASTCodeBodyHasAnalysisEntryPoints()}}46void checkASTCodeBodyHasAnalysisEntryPoints() {47 int z = 1;48 z = 2;49 // common-warning@-1 {{Value stored to 'z' is never read}}50 // textout-note@-2 {{Value stored to 'z' is never read}}51}52 53void notInvokedLambdaScope() {54 // CHECK: note: [debug] analyzing from notInvokedLambdaScope()::(anonymous class)::operator()()55 // CHECK-NEXT: | auto notInvokedLambda = []() {56 // CHECK-NEXT: | ^57 // textout-note@+1 {{[debug] analyzing from notInvokedLambdaScope()::(anonymous class)::operator()()}}58 auto notInvokedLambda = []() {59 // common-warning@+1 {{REACHABLE}} textout-note@+1 {{REACHABLE}}60 clang_analyzer_warnIfReached();61 };62 (void)notInvokedLambda; // Not invoking the lambda.63}64 65// CHECK: note: [debug] analyzing from invokedLambdaScope()66// CHECK-NEXT: | void invokedLambdaScope() {67// CHECK-NEXT: | ^68// textout-note@+1 {{[debug] analyzing from invokedLambdaScope()}}69void invokedLambdaScope() {70 auto invokedLambda = []() {71 // common-warning@+1 {{REACHABLE}} textout-note@+1 {{REACHABLE}}72 clang_analyzer_warnIfReached();73 };74 invokedLambda(); // textout-note {{Calling 'operator()'}}75}