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 7 // RUN: cp %S/Inputs/ctu-other.cpp.externalFnMap.txt %t/ctudir/externalFnMap.txt 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 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 19 // CHECK: CTU loaded AST file: {{.*}}ctu-other.cpp.ast 20 // CHECK: CTU loaded AST file: {{.*}}ctu-chain.cpp.ast 21 22 #include "ctu-hdr.h" 23 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 60 int fun_using_anon_struct(int); 61 int other_macro_diag(int); 62 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}} 78 clang_analyzer_eval(fun_using_anon_struct(8) == 8); // expected-warning{{TRUE}} 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}} 83 } 84