1 // REQUIRES: plugins
2 
3 // FIXME: This test fails on clang-stage2-cmake-RgSan,
4 // see also https://reviews.llvm.org/D62445#1613268
5 // UNSUPPORTED: darwin
6 
7 // RUN: %clang_analyze_cc1 -verify %s \
8 // RUN:   -load %llvmshlibdir/SampleAnalyzerPlugin%pluginext \
9 // RUN:   -analyzer-checker='example.MainCallChecker'
10 
11 // Test that the MainCallChecker example analyzer plugin loads and runs.
12 
13 int main();
14 
caller()15 void caller() {
16   main(); // expected-warning {{call to main}}
17 }
18 
19 // RUN: %clang_analyze_cc1 %s \
20 // RUN:   -load %llvmshlibdir/CheckerDependencyHandlingAnalyzerPlugin%pluginext\
21 // RUN:   -analyzer-checker=example.DependendentChecker \
22 // RUN:   -analyzer-list-enabled-checkers \
23 // RUN:   2>&1 | FileCheck %s -check-prefix=CHECK-IMPLICITLY-ENABLED
24 
25 // CHECK-IMPLICITLY-ENABLED: example.Dependency
26 // CHECK-IMPLICITLY-ENABLED: example.DependendentChecker
27 
28 // RUN: %clang_analyze_cc1 %s \
29 // RUN:   -load %llvmshlibdir/CheckerDependencyHandlingAnalyzerPlugin%pluginext\
30 // RUN:   -analyzer-checker=example.DependendentChecker \
31 // RUN:   -analyzer-disable-checker=example.Dependency \
32 // RUN:   -analyzer-list-enabled-checkers \
33 // RUN:   2>&1 | FileCheck %s -check-prefix=CHECK-IMPLICITLY-DISABLED
34 
35 // CHECK-IMPLICITLY-DISABLED-NOT: example.Dependency
36 // CHECK-IMPLICITLY-DISABLED-NOT: example.DependendentChecker
37 
38 // RUN: %clang_analyze_cc1 %s \
39 // RUN:   -load %llvmshlibdir/CheckerOptionHandlingAnalyzerPlugin%pluginext\
40 // RUN:   -analyzer-checker=example.MyChecker \
41 // RUN:   2>&1 | FileCheck %s -check-prefix=CHECK-CHECKER-OPTION-OUTPUT
42 
43 // CHECK-CHECKER-OPTION-OUTPUT: Example option is set to false
44 
45 // RUN: %clang_analyze_cc1 %s \
46 // RUN:   -load %llvmshlibdir/CheckerOptionHandlingAnalyzerPlugin%pluginext\
47 // RUN:   -analyzer-checker=example.MyChecker \
48 // RUN:   -analyzer-config example.MyChecker:ExampleOption=true \
49 // RUN:   2>&1 | FileCheck %s -check-prefix=CHECK-CHECKER-OPTION-OUTPUT-TRUE
50 
51 // CHECK-CHECKER-OPTION-OUTPUT-TRUE: Example option is set to true
52 
53 // RUN: %clang_analyze_cc1 %s \
54 // RUN:   -load %llvmshlibdir/CheckerOptionHandlingAnalyzerPlugin%pluginext\
55 // RUN:   -analyzer-checker=example.MyChecker \
56 // RUN:   -analyzer-checker=debug.ConfigDumper \
57 // RUN:   2>&1 | FileCheck %s -check-prefix=CHECK-CHECKER-OPTION
58 
59 // CHECK-CHECKER-OPTION: example.MyChecker:ExampleOption = false
60 
61 // RUN: %clang_analyze_cc1 %s \
62 // RUN:   -load %llvmshlibdir/CheckerOptionHandlingAnalyzerPlugin%pluginext\
63 // RUN:   -analyzer-checker=example.MyChecker \
64 // RUN:   -analyzer-checker=debug.ConfigDumper \
65 // RUN:   -analyzer-config example.MyChecker:ExampleOption=true \
66 // RUN:   2>&1 | FileCheck %s -check-prefix=CHECK-CHECKER-OPTION-TRUE
67 
68 // CHECK-CHECKER-OPTION-TRUE: example.MyChecker:ExampleOption = true
69 
70 // RUN: not %clang_analyze_cc1 -verify %s \
71 // RUN:   -load %llvmshlibdir/CheckerOptionHandlingAnalyzerPlugin%pluginext\
72 // RUN:   -analyzer-checker=example.MyChecker \
73 // RUN:   -analyzer-config example.MyChecker:Example=true \
74 // RUN:   2>&1 | FileCheck %s -check-prefix=CHECK-NON-EXISTENT-CHECKER-OPTION
75 
76 // CHECK-NON-EXISTENT-CHECKER-OPTION: (frontend): checker 'example.MyChecker'
77 // CHECK-NON-EXISTENT-CHECKER-OPTION-SAME: has no option called 'Example'
78 
79 // RUN: not %clang_analyze_cc1 -verify %s \
80 // RUN:   -load %llvmshlibdir/CheckerOptionHandlingAnalyzerPlugin%pluginext\
81 // RUN:   -analyzer-checker=example.MyChecker \
82 // RUN:   -analyzer-config-compatibility-mode=true \
83 // RUN:   -analyzer-config example.MyChecker:Example=true
84 
85 
86 // RUN: not %clang_analyze_cc1 -verify %s \
87 // RUN:   -load %llvmshlibdir/CheckerOptionHandlingAnalyzerPlugin%pluginext\
88 // RUN:   -analyzer-checker=example.MyChecker \
89 // RUN:   -analyzer-config example.MyChecker:ExampleOption=example \
90 // RUN:   2>&1 | FileCheck %s -check-prefix=CHECK-INVALID-BOOL-VALUE
91 
92 // CHECK-INVALID-BOOL-VALUE: (frontend): invalid input for checker option
93 // CHECK-INVALID-BOOL-VALUE-SAME: 'example.MyChecker:ExampleOption', that
94 // CHECK-INVALID-BOOL-VALUE-SAME: expects a boolean value
95 
96 // RUN: not %clang_analyze_cc1 -verify %s \
97 // RUN:   -load %llvmshlibdir/CheckerOptionHandlingAnalyzerPlugin%pluginext\
98 // RUN:   -analyzer-checker=example.MyChecker \
99 // RUN:   -analyzer-config-compatibility-mode=true \
100 // RUN:   -analyzer-config example.MyChecker:ExampleOption=example
101 
102 // RUN: %clang_analyze_cc1 %s \
103 // RUN:   -load %llvmshlibdir/CheckerOptionHandlingAnalyzerPlugin%pluginext\
104 // RUN:   -analyzer-checker=example.MyChecker \
105 // RUN:   -analyzer-checker=debug.ConfigDumper \
106 // RUN:   -analyzer-config-compatibility-mode=true \
107 // RUN:   -analyzer-config example.MyChecker:ExampleOption=example \
108 // RUN:   2>&1 | FileCheck %s -check-prefix=CHECK-CORRECTED-BOOL-VALUE
109 
110 // CHECK-CORRECTED-BOOL-VALUE: example.MyChecker:ExampleOption = false
111 
112 // RUN: %clang_analyze_cc1 %s \
113 // RUN:   -load %llvmshlibdir/CheckerOptionHandlingAnalyzerPlugin%pluginext\
114 // RUN:   -analyzer-checker=example.MyChecker \
115 // RUN:   -analyzer-checker-option-help \
116 // RUN:   2>&1 | FileCheck %s -check-prefix=CHECK-CHECKER-OPTION-HELP
117 
118 // CHECK-CHECKER-OPTION-HELP: example.MyChecker:ExampleOption  (bool) This is an
119 // CHECK-CHECKER-OPTION-HELP-SAME: example checker opt. (default: false)
120