blob: 44c0c07603d7c231e735d3cb33082b34f09ad21f [file] [log] [blame]
Gabor Marton681bcb62018-12-07 12:29:02 +00001// 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 Martonb87251d2018-12-07 16:05:58 +00007// RUN: cp %S/Inputs/ctu-other.cpp.externalFnMap.txt %t/ctudir/externalFnMap.txt
Gabor Marton681bcb62018-12-07 12:29:02 +00008// 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 Marton9419eb42018-12-07 14:56:02 +000013// 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 Marton30388d62018-12-07 17:36:44 +000019// CHECK: CTU loaded AST file: {{.*}}ctu-other.cpp.ast
20// CHECK: CTU loaded AST file: {{.*}}ctu-chain.cpp.ast
Ilya Biryukov8b9b3bd2018-03-01 14:54:16 +000021
Rafael Stahl67676e92018-07-04 14:12:58 +000022#include "ctu-hdr.h"
23
Ilya Biryukov8b9b3bd2018-03-01 14:54:16 +000024void clang_analyzer_eval(int);
25
26int f(int);
27int g(int);
28int h(int);
29
30int callback_to_main(int x) { return x + 1; }
31
32namespace myns {
33int fns(int x);
34
35namespace embed_ns {
36int fens(int x);
37}
38
39class embed_cls {
40public:
41 int fecl(int x);
42};
43}
44
45class mycls {
46public:
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
56namespace chns {
57int chf1(int x);
58}
59
Aleksei Sidorin04fbffc2018-04-24 10:11:53 +000060int fun_using_anon_struct(int);
Rafael Stahl67676e92018-07-04 14:12:58 +000061int other_macro_diag(int);
Aleksei Sidorin04fbffc2018-04-24 10:11:53 +000062
Ilya Biryukov8b9b3bd2018-03-01 14:54:16 +000063int 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 Sidorin04fbffc2018-04-24 10:11:53 +000078 clang_analyzer_eval(fun_using_anon_struct(8) == 8); // expected-warning{{TRUE}}
Rafael Stahl67676e92018-07-04 14:12:58 +000079
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 Biryukov8b9b3bd2018-03-01 14:54:16 +000083}