1 // RUN: rm -rf %t && mkdir %t
2 // RUN: mkdir -p %t/ctudir
3 // RUN: %clang_cc1 -std=c++14 -triple x86_64-pc-linux-gnu \
4 // RUN: -emit-pch -o %t/ctudir/ctu-other.cpp.ast %S/Inputs/ctu-other.cpp
5 // RUN: %clang_cc1 -std=c++14 -triple x86_64-pc-linux-gnu \
6 // RUN: -emit-pch -o %t/ctudir/ctu-chain.cpp.ast %S/Inputs/ctu-chain.cpp
7 // RUN: cp %S/Inputs/ctu-other.cpp.externalDefMap.ast-dump.txt %t/ctudir/externalDefMap.txt
8 // RUN: %clang_analyze_cc1 -std=c++14 -triple x86_64-pc-linux-gnu \
9 // RUN: -analyzer-checker=core,debug.ExprInspection \
10 // RUN: -analyzer-config experimental-enable-naive-ctu-analysis=true \
11 // RUN: -analyzer-config ctu-dir=%t/ctudir \
13 // RUN: %clang_analyze_cc1 -std=c++14 -triple x86_64-pc-linux-gnu \
14 // RUN: -analyzer-checker=core,debug.ExprInspection \
15 // RUN: -analyzer-config experimental-enable-naive-ctu-analysis=true \
16 // RUN: -analyzer-config ctu-dir=%t/ctudir \
17 // RUN: -analyzer-config display-ctu-progress=true 2>&1 %s | FileCheck %s
19 // CHECK: CTU loaded AST file: {{.*}}ctu-other.cpp.ast
20 // CHECK: CTU loaded AST file: {{.*}}ctu-chain.cpp.ast
24 void clang_analyzer_eval(int);
30 int callback_to_main(int x
) { return x
+ 1; }
48 virtual int fvcl(int x
);
49 static int fscl(int x
);
57 class derived
: public mycls
{
59 virtual int fvcl(int x
) override
;
66 int fun_using_anon_struct(int);
67 int other_macro_diag(int);
69 extern const int extInt
;
71 extern const int extInt
;
77 extern const int extHere
;
78 const int extHere
= 6;
95 extern SCNest::SCN extSubSCN
;
103 const unsigned int b
;
107 void test_virtual_functions(mycls
* obj
) {
108 // The dynamic type is known.
109 clang_analyzer_eval(mycls().fvcl(1) == 8); // expected-warning{{TRUE}}
110 clang_analyzer_eval(derived().fvcl(1) == 9); // expected-warning{{TRUE}}
111 // We cannot decide about the dynamic type.
112 clang_analyzer_eval(obj
->fvcl(1) == 8); // expected-warning{{FALSE}} expected-warning{{TRUE}}
115 class TestAnonUnionUSR
{
117 inline float f(int value
) {
125 static const int Test
;
128 extern int testImportOfIncompleteDefaultParmDuringImport(int);
130 extern int testImportOfDelegateConstructor(int);
133 clang_analyzer_eval(f(3) == 2); // expected-warning{{TRUE}}
134 clang_analyzer_eval(f(4) == 3); // expected-warning{{TRUE}}
135 clang_analyzer_eval(f(5) == 3); // expected-warning{{FALSE}}
136 clang_analyzer_eval(g(4) == 6); // expected-warning{{TRUE}}
137 clang_analyzer_eval(h(2) == 8); // expected-warning{{TRUE}}
139 clang_analyzer_eval(myns::fns(2) == 9); // expected-warning{{TRUE}}
140 clang_analyzer_eval(myns::embed_ns::fens(2) == -1); // expected-warning{{TRUE}}
141 clang_analyzer_eval(mycls().fcl(1) == 6); // expected-warning{{TRUE}}
142 clang_analyzer_eval(mycls::fscl(1) == 7); // expected-warning{{TRUE}}
143 clang_analyzer_eval(myns::embed_cls().fecl(1) == -6); // expected-warning{{TRUE}}
144 clang_analyzer_eval(mycls::embed_cls2().fecl2(0) == -11); // expected-warning{{TRUE}}
146 clang_analyzer_eval(chns::chf1(4) == 12); // expected-warning{{TRUE}}
147 clang_analyzer_eval(fun_using_anon_struct(8) == 8); // expected-warning{{TRUE}}
149 clang_analyzer_eval(other_macro_diag(1) == 1); // expected-warning{{TRUE}}
150 // expected-warning@Inputs/ctu-other.cpp:93{{REACHABLE}}
151 MACRODIAG(); // expected-warning{{REACHABLE}}
153 clang_analyzer_eval(extInt
== 2); // expected-warning{{TRUE}}
154 clang_analyzer_eval(intns::extInt
== 3); // expected-warning{{TRUE}}
155 clang_analyzer_eval(extS
.a
== 4); // expected-warning{{TRUE}}
156 clang_analyzer_eval(extHere
== 6); // expected-warning{{TRUE}}
157 clang_analyzer_eval(A::a
== 3); // expected-warning{{TRUE}}
158 clang_analyzer_eval(extSC
.a
== 8); // expected-warning{{TRUE}}
159 clang_analyzer_eval(ST::sc
.a
== 2); // expected-warning{{TRUE}}
160 // clang_analyzer_eval(extSCN.scn.a == 9); // TODO
161 clang_analyzer_eval(extSubSCN
.a
== 1); // expected-warning{{TRUE}}
162 // clang_analyzer_eval(extSCC.a == 7); // TODO
163 clang_analyzer_eval(extU
.a
== 4); // expected-warning{{TRUE}}
165 clang_analyzer_eval(TestAnonUnionUSR::Test
== 5); // expected-warning{{TRUE}}
167 clang_analyzer_eval(testImportOfIncompleteDefaultParmDuringImport(9) == 9); // expected-warning{{TRUE}}
169 clang_analyzer_eval(testImportOfDelegateConstructor(10) == 10); // expected-warning{{TRUE}}