Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / Analysis / flexible-array-member.cpp
blob10ca64bc438059317e7e7e0fd6f9f4b43c0a25f3
1 // RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -std=c++11 -verify %s
2 // RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -std=c++17 -verify %s
4 #include "Inputs/system-header-simulator-cxx.h"
6 void clang_analyzer_eval(bool);
8 struct S
10 static int c;
11 static int d;
12 int x;
13 S() { x = c++; }
14 ~S() { d++; }
17 int S::c = 0;
18 int S::d = 0;
20 struct Flex
22 int length;
23 S contents[0];
26 void flexibleArrayMember()
28 S::c = 0;
29 S::d = 0;
31 const int size = 4;
33 Flex *arr =
34 (Flex *)::operator new(__builtin_offsetof(Flex, contents) + sizeof(S) * size);
36 clang_analyzer_eval(S::c == 0); // expected-warning{{TRUE}}
38 new (&arr->contents[0]) S;
39 new (&arr->contents[1]) S;
40 new (&arr->contents[2]) S;
41 new (&arr->contents[3]) S;
43 clang_analyzer_eval(S::c == size); // expected-warning{{TRUE}}
45 clang_analyzer_eval(arr->contents[0].x == 0); // expected-warning{{TRUE}}
46 clang_analyzer_eval(arr->contents[1].x == 1); // expected-warning{{TRUE}}
47 clang_analyzer_eval(arr->contents[2].x == 2); // expected-warning{{TRUE}}
48 clang_analyzer_eval(arr->contents[3].x == 3); // expected-warning{{TRUE}}
50 arr->contents[0].~S();
51 arr->contents[1].~S();
52 arr->contents[2].~S();
53 arr->contents[3].~S();
55 ::operator delete(arr);
57 clang_analyzer_eval(S::d == size); // expected-warning{{TRUE}}