2 // RUN: mkdir -p %t/Inputs
3 // RUN: cp %s %t/ctu-on-demand-parsing.cpp
4 // RUN: cp %S/ctu-hdr.h %t/ctu-hdr.h
5 // RUN: cp %S/Inputs/ctu-chain.cpp %t/Inputs/ctu-chain.cpp
6 // RUN: cp %S/Inputs/ctu-other.cpp %t/Inputs/ctu-other.cpp
8 // Path substitutions on Windows platform could contain backslashes. These are escaped in the json file.
9 // compile_commands.json is only needed for the extdef_mapping, not for the analysis itself.
10 // RUN: echo '[{"directory":"%t/Inputs","command":"clang++ ctu-chain.cpp","file":"ctu-chain.cpp"},{"directory":"%t/Inputs","command":"clang++ ctu-other.cpp","file":"ctu-other.cpp"}]' | sed -e 's/\\/\\\\/g' > %t/compile_commands.json
12 // RUN: echo '{"%t/Inputs/ctu-chain.cpp": ["g++", "%t/Inputs/ctu-chain.cpp"], "%t/Inputs/ctu-other.cpp": ["g++", "%t/Inputs/ctu-other.cpp"]}' | sed -e 's/\\/\\\\/g' > %t/invocations.yaml
14 // RUN: cd "%t" && %clang_extdef_map Inputs/ctu-chain.cpp Inputs/ctu-other.cpp > externalDefMap.txt
16 // RUN: cd "%t" && %clang_analyze_cc1 \
17 // RUN: -analyzer-checker=core,debug.ExprInspection \
18 // RUN: -analyzer-config experimental-enable-naive-ctu-analysis=true \
19 // RUN: -analyzer-config ctu-dir=. \
20 // RUN: -analyzer-config ctu-invocation-list=invocations.yaml \
21 // RUN: -analyzer-config ctu-phase1-inlining=all \
22 // RUN: -verify ctu-on-demand-parsing.cpp
23 // RUN: cd "%t" && %clang_analyze_cc1 \
24 // RUN: -analyzer-checker=core,debug.ExprInspection \
25 // RUN: -analyzer-config experimental-enable-naive-ctu-analysis=true \
26 // RUN: -analyzer-config ctu-dir=. \
27 // RUN: -analyzer-config ctu-invocation-list=invocations.yaml \
28 // RUN: -analyzer-config display-ctu-progress=true ctu-on-demand-parsing.cpp 2>&1 | FileCheck %t/ctu-on-demand-parsing.cpp
30 // CHECK: CTU loaded AST file: {{.*}}ctu-other.cpp
31 // CHECK: CTU loaded AST file: {{.*}}ctu-chain.cpp
33 // FIXME: On-demand ctu should be tested in the same file that we have for the
34 // PCH version, but with a different verify prefix (e.g. -verfiy=on-demand-ctu)
36 // FIXME: Path handling should work on all platforms.
37 // REQUIRES: system-linux
41 void clang_analyzer_eval(int);
47 int callback_to_main(int x
) { return x
+ 1; }
65 virtual int fvcl(int x
);
66 static int fscl(int x
);
74 class derived
: public mycls
{
76 virtual int fvcl(int x
) override
;
83 int fun_using_anon_struct(int);
84 int other_macro_diag(int);
86 void test_virtual_functions(mycls
*obj
) {
87 // The dynamic type is known.
88 clang_analyzer_eval(mycls().fvcl(1) == 8); // expected-warning{{TRUE}}
89 clang_analyzer_eval(derived().fvcl(1) == 9); // expected-warning{{TRUE}}
90 // We cannot decide about the dynamic type.
91 clang_analyzer_eval(obj
->fvcl(1) == 8); // expected-warning{{FALSE}} expected-warning{{TRUE}}
92 clang_analyzer_eval(obj
->fvcl(1) == 9); // expected-warning{{FALSE}} expected-warning{{TRUE}}
96 clang_analyzer_eval(f(3) == 2); // expected-warning{{TRUE}}
97 clang_analyzer_eval(f(4) == 3); // expected-warning{{TRUE}}
98 clang_analyzer_eval(f(5) == 3); // expected-warning{{FALSE}}
99 clang_analyzer_eval(g(4) == 6); // expected-warning{{TRUE}}
100 clang_analyzer_eval(h(2) == 8); // expected-warning{{TRUE}}
102 clang_analyzer_eval(myns::fns(2) == 9); // expected-warning{{TRUE}}
103 clang_analyzer_eval(myns::embed_ns::fens(2) == -1); // expected-warning{{TRUE}}
104 clang_analyzer_eval(mycls().fcl(1) == 6); // expected-warning{{TRUE}}
105 clang_analyzer_eval(mycls::fscl(1) == 7); // expected-warning{{TRUE}}
106 clang_analyzer_eval(myns::embed_cls().fecl(1) == -6); // expected-warning{{TRUE}}
107 clang_analyzer_eval(mycls::embed_cls2().fecl2(0) == -11); // expected-warning{{TRUE}}
109 clang_analyzer_eval(chns::chf1(4) == 12); // expected-warning{{TRUE}}
110 clang_analyzer_eval(fun_using_anon_struct(8) == 8); // expected-warning{{TRUE}}
112 clang_analyzer_eval(other_macro_diag(1) == 1); // expected-warning{{TRUE}}
113 // expected-warning@Inputs/ctu-other.cpp:93{{REACHABLE}}
114 MACRODIAG(); // expected-warning{{REACHABLE}}