Ilya Biryukov | 8b9b3bd | 2018-03-01 14:54:16 +0000 | [diff] [blame] | 1 | // RUN: mkdir -p %T/ctudir |
| 2 | // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -emit-pch -o %T/ctudir/ctu-other.cpp.ast %S/Inputs/ctu-other.cpp |
| 3 | // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -emit-pch -o %T/ctudir/ctu-chain.cpp.ast %S/Inputs/ctu-chain.cpp |
| 4 | // RUN: cp %S/Inputs/externalFnMap.txt %T/ctudir/ |
| 5 | // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fsyntax-only -analyze -analyzer-checker=core,debug.ExprInspection -analyzer-config experimental-enable-naive-ctu-analysis=true -analyzer-config ctu-dir=%T/ctudir -verify %s |
| 6 | |
Rafael Stahl | 67676e9 | 2018-07-04 14:12:58 +0000 | [diff] [blame] | 7 | #include "ctu-hdr.h" |
| 8 | |
Ilya Biryukov | 8b9b3bd | 2018-03-01 14:54:16 +0000 | [diff] [blame] | 9 | void clang_analyzer_eval(int); |
| 10 | |
| 11 | int f(int); |
| 12 | int g(int); |
| 13 | int h(int); |
| 14 | |
| 15 | int callback_to_main(int x) { return x + 1; } |
| 16 | |
| 17 | namespace myns { |
| 18 | int fns(int x); |
| 19 | |
| 20 | namespace embed_ns { |
| 21 | int fens(int x); |
| 22 | } |
| 23 | |
| 24 | class embed_cls { |
| 25 | public: |
| 26 | int fecl(int x); |
| 27 | }; |
| 28 | } |
| 29 | |
| 30 | class mycls { |
| 31 | public: |
| 32 | int fcl(int x); |
| 33 | static int fscl(int x); |
| 34 | |
| 35 | class embed_cls2 { |
| 36 | public: |
| 37 | int fecl2(int x); |
| 38 | }; |
| 39 | }; |
| 40 | |
| 41 | namespace chns { |
| 42 | int chf1(int x); |
| 43 | } |
| 44 | |
Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 45 | int fun_using_anon_struct(int); |
Rafael Stahl | 67676e9 | 2018-07-04 14:12:58 +0000 | [diff] [blame] | 46 | int other_macro_diag(int); |
Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 47 | |
Ilya Biryukov | 8b9b3bd | 2018-03-01 14:54:16 +0000 | [diff] [blame] | 48 | int main() { |
| 49 | clang_analyzer_eval(f(3) == 2); // expected-warning{{TRUE}} |
| 50 | clang_analyzer_eval(f(4) == 3); // expected-warning{{TRUE}} |
| 51 | clang_analyzer_eval(f(5) == 3); // expected-warning{{FALSE}} |
| 52 | clang_analyzer_eval(g(4) == 6); // expected-warning{{TRUE}} |
| 53 | clang_analyzer_eval(h(2) == 8); // expected-warning{{TRUE}} |
| 54 | |
| 55 | clang_analyzer_eval(myns::fns(2) == 9); // expected-warning{{TRUE}} |
| 56 | clang_analyzer_eval(myns::embed_ns::fens(2) == -1); // expected-warning{{TRUE}} |
| 57 | clang_analyzer_eval(mycls().fcl(1) == 6); // expected-warning{{TRUE}} |
| 58 | clang_analyzer_eval(mycls::fscl(1) == 7); // expected-warning{{TRUE}} |
| 59 | clang_analyzer_eval(myns::embed_cls().fecl(1) == -6); // expected-warning{{TRUE}} |
| 60 | clang_analyzer_eval(mycls::embed_cls2().fecl2(0) == -11); // expected-warning{{TRUE}} |
| 61 | |
| 62 | clang_analyzer_eval(chns::chf1(4) == 12); // expected-warning{{TRUE}} |
Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 63 | clang_analyzer_eval(fun_using_anon_struct(8) == 8); // expected-warning{{TRUE}} |
Rafael Stahl | 67676e9 | 2018-07-04 14:12:58 +0000 | [diff] [blame] | 64 | |
| 65 | clang_analyzer_eval(other_macro_diag(1) == 1); // expected-warning{{TRUE}} |
| 66 | // expected-warning@Inputs/ctu-other.cpp:75{{REACHABLE}} |
| 67 | MACRODIAG(); // expected-warning{{REACHABLE}} |
Ilya Biryukov | 8b9b3bd | 2018-03-01 14:54:16 +0000 | [diff] [blame] | 68 | } |