Gabor Marton | 681bcb6 | 2018-12-07 12:29:02 +0000 | [diff] [blame] | 1 | // RUN: rm -rf %t && mkdir %t |
| 2 | // RUN: mkdir -p %t/ctudir |
| 3 | // RUN: %clang_cc1 -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 -triple x86_64-pc-linux-gnu \ |
| 6 | // RUN: -emit-pch -o %t/ctudir/ctu-chain.cpp.ast %S/Inputs/ctu-chain.cpp |
Gabor Marton | b87251d | 2018-12-07 16:05:58 +0000 | [diff] [blame] | 7 | // RUN: cp %S/Inputs/ctu-other.cpp.externalFnMap.txt %t/ctudir/externalFnMap.txt |
Gabor Marton | 681bcb6 | 2018-12-07 12:29:02 +0000 | [diff] [blame] | 8 | // RUN: %clang_analyze_cc1 -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 \ |
| 12 | // RUN: -verify %s |
Gabor Marton | 9419eb4 | 2018-12-07 14:56:02 +0000 | [diff] [blame] | 13 | // RUN: %clang_analyze_cc1 -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 |
| 18 | |
Gabor Marton | 30388d6 | 2018-12-07 17:36:44 +0000 | [diff] [blame] | 19 | // CHECK: CTU loaded AST file: {{.*}}ctu-other.cpp.ast |
| 20 | // CHECK: CTU loaded AST file: {{.*}}ctu-chain.cpp.ast |
Ilya Biryukov | 8b9b3bd | 2018-03-01 14:54:16 +0000 | [diff] [blame] | 21 | |
Rafael Stahl | 67676e9 | 2018-07-04 14:12:58 +0000 | [diff] [blame] | 22 | #include "ctu-hdr.h" |
| 23 | |
Ilya Biryukov | 8b9b3bd | 2018-03-01 14:54:16 +0000 | [diff] [blame] | 24 | void clang_analyzer_eval(int); |
| 25 | |
| 26 | int f(int); |
| 27 | int g(int); |
| 28 | int h(int); |
| 29 | |
| 30 | int callback_to_main(int x) { return x + 1; } |
| 31 | |
| 32 | namespace myns { |
| 33 | int fns(int x); |
| 34 | |
| 35 | namespace embed_ns { |
| 36 | int fens(int x); |
| 37 | } |
| 38 | |
| 39 | class embed_cls { |
| 40 | public: |
| 41 | int fecl(int x); |
| 42 | }; |
| 43 | } |
| 44 | |
| 45 | class mycls { |
| 46 | public: |
| 47 | int fcl(int x); |
| 48 | static int fscl(int x); |
| 49 | |
| 50 | class embed_cls2 { |
| 51 | public: |
| 52 | int fecl2(int x); |
| 53 | }; |
| 54 | }; |
| 55 | |
| 56 | namespace chns { |
| 57 | int chf1(int x); |
| 58 | } |
| 59 | |
Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 60 | int fun_using_anon_struct(int); |
Rafael Stahl | 67676e9 | 2018-07-04 14:12:58 +0000 | [diff] [blame] | 61 | int other_macro_diag(int); |
Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 62 | |
Ilya Biryukov | 8b9b3bd | 2018-03-01 14:54:16 +0000 | [diff] [blame] | 63 | int main() { |
| 64 | clang_analyzer_eval(f(3) == 2); // expected-warning{{TRUE}} |
| 65 | clang_analyzer_eval(f(4) == 3); // expected-warning{{TRUE}} |
| 66 | clang_analyzer_eval(f(5) == 3); // expected-warning{{FALSE}} |
| 67 | clang_analyzer_eval(g(4) == 6); // expected-warning{{TRUE}} |
| 68 | clang_analyzer_eval(h(2) == 8); // expected-warning{{TRUE}} |
| 69 | |
| 70 | clang_analyzer_eval(myns::fns(2) == 9); // expected-warning{{TRUE}} |
| 71 | clang_analyzer_eval(myns::embed_ns::fens(2) == -1); // expected-warning{{TRUE}} |
| 72 | clang_analyzer_eval(mycls().fcl(1) == 6); // expected-warning{{TRUE}} |
| 73 | clang_analyzer_eval(mycls::fscl(1) == 7); // expected-warning{{TRUE}} |
| 74 | clang_analyzer_eval(myns::embed_cls().fecl(1) == -6); // expected-warning{{TRUE}} |
| 75 | clang_analyzer_eval(mycls::embed_cls2().fecl2(0) == -11); // expected-warning{{TRUE}} |
| 76 | |
| 77 | clang_analyzer_eval(chns::chf1(4) == 12); // expected-warning{{TRUE}} |
Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 78 | clang_analyzer_eval(fun_using_anon_struct(8) == 8); // expected-warning{{TRUE}} |
Rafael Stahl | 67676e9 | 2018-07-04 14:12:58 +0000 | [diff] [blame] | 79 | |
| 80 | clang_analyzer_eval(other_macro_diag(1) == 1); // expected-warning{{TRUE}} |
| 81 | // expected-warning@Inputs/ctu-other.cpp:75{{REACHABLE}} |
| 82 | MACRODIAG(); // expected-warning{{REACHABLE}} |
Ilya Biryukov | 8b9b3bd | 2018-03-01 14:54:16 +0000 | [diff] [blame] | 83 | } |