[clang-cl] Ignore /Wv and /Wv:17 flags
[llvm-project.git] / clang / test / Analysis / ctu-main.cpp
blobd76b3984401e0de8e3626225d68412f8d4c4ba00
1 // RUN: rm -rf %t && mkdir %t
2 // RUN: mkdir -p %t/ctudir
3 // RUN: %clang_cc1 -std=c++14 -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 -std=c++14 -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.externalDefMap.ast-dump.txt %t/ctudir/externalDefMap.txt
8 // RUN: %clang_analyze_cc1 -std=c++14 -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 -std=c++14 -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
19 // CHECK: CTU loaded AST file: {{.*}}ctu-other.cpp.ast
20 // CHECK: CTU loaded AST file: {{.*}}ctu-chain.cpp.ast
22 #include "ctu-hdr.h"
24 void clang_analyzer_eval(int);
26 int f(int);
27 int g(int);
28 int h(int);
30 int callback_to_main(int x) { return x + 1; }
32 namespace myns {
33 int fns(int x);
35 namespace embed_ns {
36 int fens(int x);
39 class embed_cls {
40 public:
41 int fecl(int x);
45 class mycls {
46 public:
47 int fcl(int x);
48 virtual int fvcl(int x);
49 static int fscl(int x);
51 class embed_cls2 {
52 public:
53 int fecl2(int x);
57 class derived : public mycls {
58 public:
59 virtual int fvcl(int x) override;
62 namespace chns {
63 int chf1(int x);
66 int fun_using_anon_struct(int);
67 int other_macro_diag(int);
69 extern const int extInt;
70 namespace intns {
71 extern const int extInt;
73 struct S {
74 int a;
76 extern const S extS;
77 extern const int extHere;
78 const int extHere = 6;
79 struct A {
80 static const int a;
82 struct SC {
83 const int a;
85 extern SC extSC;
86 struct ST {
87 static struct SC sc;
89 struct SCNest {
90 struct SCN {
91 const int a;
92 } scn;
94 extern SCNest extSCN;
95 extern SCNest::SCN extSubSCN;
96 struct SCC {
97 SCC(int c);
98 const int a;
100 extern SCC extSCC;
101 union U {
102 const int a;
103 const unsigned int b;
105 extern U extU;
107 void test_virtual_functions(mycls* obj) {
108 // The dynamic type is known.
109 clang_analyzer_eval(mycls().fvcl(1) == 8); // expected-warning{{TRUE}}
110 clang_analyzer_eval(derived().fvcl(1) == 9); // expected-warning{{TRUE}}
111 // We cannot decide about the dynamic type.
112 clang_analyzer_eval(obj->fvcl(1) == 8); // expected-warning{{FALSE}} expected-warning{{TRUE}}
115 class TestAnonUnionUSR {
116 public:
117 inline float f(int value) {
118 union {
119 float f;
120 int i;
122 i = value;
123 return f;
125 static const int Test;
128 extern int testImportOfIncompleteDefaultParmDuringImport(int);
130 extern int testImportOfDelegateConstructor(int);
132 int main() {
133 clang_analyzer_eval(f(3) == 2); // expected-warning{{TRUE}}
134 clang_analyzer_eval(f(4) == 3); // expected-warning{{TRUE}}
135 clang_analyzer_eval(f(5) == 3); // expected-warning{{FALSE}}
136 clang_analyzer_eval(g(4) == 6); // expected-warning{{TRUE}}
137 clang_analyzer_eval(h(2) == 8); // expected-warning{{TRUE}}
139 clang_analyzer_eval(myns::fns(2) == 9); // expected-warning{{TRUE}}
140 clang_analyzer_eval(myns::embed_ns::fens(2) == -1); // expected-warning{{TRUE}}
141 clang_analyzer_eval(mycls().fcl(1) == 6); // expected-warning{{TRUE}}
142 clang_analyzer_eval(mycls::fscl(1) == 7); // expected-warning{{TRUE}}
143 clang_analyzer_eval(myns::embed_cls().fecl(1) == -6); // expected-warning{{TRUE}}
144 clang_analyzer_eval(mycls::embed_cls2().fecl2(0) == -11); // expected-warning{{TRUE}}
146 clang_analyzer_eval(chns::chf1(4) == 12); // expected-warning{{TRUE}}
147 clang_analyzer_eval(fun_using_anon_struct(8) == 8); // expected-warning{{TRUE}}
149 clang_analyzer_eval(other_macro_diag(1) == 1); // expected-warning{{TRUE}}
150 // expected-warning@Inputs/ctu-other.cpp:93{{REACHABLE}}
151 MACRODIAG(); // expected-warning{{REACHABLE}}
153 clang_analyzer_eval(extInt == 2); // expected-warning{{TRUE}}
154 clang_analyzer_eval(intns::extInt == 3); // expected-warning{{TRUE}}
155 clang_analyzer_eval(extS.a == 4); // expected-warning{{TRUE}}
156 clang_analyzer_eval(extHere == 6); // expected-warning{{TRUE}}
157 clang_analyzer_eval(A::a == 3); // expected-warning{{TRUE}}
158 clang_analyzer_eval(extSC.a == 8); // expected-warning{{TRUE}}
159 clang_analyzer_eval(ST::sc.a == 2); // expected-warning{{TRUE}}
160 // clang_analyzer_eval(extSCN.scn.a == 9); // TODO
161 clang_analyzer_eval(extSubSCN.a == 1); // expected-warning{{TRUE}}
162 // clang_analyzer_eval(extSCC.a == 7); // TODO
163 clang_analyzer_eval(extU.a == 4); // expected-warning{{TRUE}}
165 clang_analyzer_eval(TestAnonUnionUSR::Test == 5); // expected-warning{{TRUE}}
167 clang_analyzer_eval(testImportOfIncompleteDefaultParmDuringImport(9) == 9); // expected-warning{{TRUE}}
169 clang_analyzer_eval(testImportOfDelegateConstructor(10) == 10); // expected-warning{{TRUE}}