Endre Fülöp | 5cc1851 | 2020-06-10 08:59:04 +0200 | [diff] [blame] | 1 | // RUN: rm -rf %t |
| 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 |
| 7 | // |
| 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 |
| 11 | // |
| 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 |
| 13 | // |
| 14 | // RUN: cd "%t" && %clang_extdef_map Inputs/ctu-chain.cpp Inputs/ctu-other.cpp > externalDefMap.txt |
| 15 | // |
| 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: -verify ctu-on-demand-parsing.cpp |
| 22 | // RUN: cd "%t" && %clang_analyze_cc1 \ |
| 23 | // RUN: -analyzer-checker=core,debug.ExprInspection \ |
| 24 | // RUN: -analyzer-config experimental-enable-naive-ctu-analysis=true \ |
| 25 | // RUN: -analyzer-config ctu-dir=. \ |
| 26 | // RUN: -analyzer-config ctu-invocation-list=invocations.yaml \ |
| 27 | // RUN: -analyzer-config display-ctu-progress=true ctu-on-demand-parsing.cpp 2>&1 | FileCheck %t/ctu-on-demand-parsing.cpp |
| 28 | // |
| 29 | // CHECK: CTU loaded AST file: {{.*}}ctu-other.cpp |
| 30 | // CHECK: CTU loaded AST file: {{.*}}ctu-chain.cpp |
| 31 | // |
| 32 | // FIXME: Path handling should work on all platforms. |
Balazs Benics | d96a47c | 2020-07-13 14:29:47 +0200 | [diff] [blame] | 33 | // REQUIRES: system-linux |
Endre Fülöp | 5cc1851 | 2020-06-10 08:59:04 +0200 | [diff] [blame] | 34 | |
| 35 | #include "ctu-hdr.h" |
| 36 | |
| 37 | void clang_analyzer_eval(int); |
| 38 | |
| 39 | int f(int); |
| 40 | int g(int); |
| 41 | int h(int); |
| 42 | |
| 43 | int callback_to_main(int x) { return x + 1; } |
| 44 | |
| 45 | namespace myns { |
| 46 | int fns(int x); |
| 47 | |
| 48 | namespace embed_ns { |
| 49 | int fens(int x); |
| 50 | } |
| 51 | |
| 52 | class embed_cls { |
| 53 | public: |
| 54 | int fecl(int x); |
| 55 | }; |
| 56 | } // namespace myns |
| 57 | |
| 58 | class mycls { |
| 59 | public: |
| 60 | int fcl(int x); |
| 61 | virtual int fvcl(int x); |
| 62 | static int fscl(int x); |
| 63 | |
| 64 | class embed_cls2 { |
| 65 | public: |
| 66 | int fecl2(int x); |
| 67 | }; |
| 68 | }; |
| 69 | |
| 70 | class derived : public mycls { |
| 71 | public: |
| 72 | virtual int fvcl(int x) override; |
| 73 | }; |
| 74 | |
| 75 | namespace chns { |
| 76 | int chf1(int x); |
| 77 | } |
| 78 | |
| 79 | int fun_using_anon_struct(int); |
| 80 | int other_macro_diag(int); |
| 81 | |
| 82 | void test_virtual_functions(mycls *obj) { |
| 83 | // The dynamic type is known. |
| 84 | clang_analyzer_eval(mycls().fvcl(1) == 8); // expected-warning{{TRUE}} |
| 85 | clang_analyzer_eval(derived().fvcl(1) == 9); // expected-warning{{TRUE}} |
| 86 | // We cannot decide about the dynamic type. |
| 87 | clang_analyzer_eval(obj->fvcl(1) == 8); // expected-warning{{FALSE}} expected-warning{{TRUE}} |
| 88 | clang_analyzer_eval(obj->fvcl(1) == 9); // expected-warning{{FALSE}} expected-warning{{TRUE}} |
| 89 | } |
| 90 | |
| 91 | int main() { |
| 92 | clang_analyzer_eval(f(3) == 2); // expected-warning{{TRUE}} |
| 93 | clang_analyzer_eval(f(4) == 3); // expected-warning{{TRUE}} |
| 94 | clang_analyzer_eval(f(5) == 3); // expected-warning{{FALSE}} |
| 95 | clang_analyzer_eval(g(4) == 6); // expected-warning{{TRUE}} |
| 96 | clang_analyzer_eval(h(2) == 8); // expected-warning{{TRUE}} |
| 97 | |
| 98 | clang_analyzer_eval(myns::fns(2) == 9); // expected-warning{{TRUE}} |
| 99 | clang_analyzer_eval(myns::embed_ns::fens(2) == -1); // expected-warning{{TRUE}} |
| 100 | clang_analyzer_eval(mycls().fcl(1) == 6); // expected-warning{{TRUE}} |
| 101 | clang_analyzer_eval(mycls::fscl(1) == 7); // expected-warning{{TRUE}} |
| 102 | clang_analyzer_eval(myns::embed_cls().fecl(1) == -6); // expected-warning{{TRUE}} |
| 103 | clang_analyzer_eval(mycls::embed_cls2().fecl2(0) == -11); // expected-warning{{TRUE}} |
| 104 | |
| 105 | clang_analyzer_eval(chns::chf1(4) == 12); // expected-warning{{TRUE}} |
| 106 | clang_analyzer_eval(fun_using_anon_struct(8) == 8); // expected-warning{{TRUE}} |
| 107 | |
| 108 | clang_analyzer_eval(other_macro_diag(1) == 1); // expected-warning{{TRUE}} |
| 109 | // expected-warning@Inputs/ctu-other.cpp:93{{REACHABLE}} |
| 110 | MACRODIAG(); // expected-warning{{REACHABLE}} |
| 111 | } |