1 // -fstrict-flex-arrays=2 means that only undefined or zero element arrays are considered as FAMs.
3 // RUN: %clang_analyze_cc1 -triple x86_64-linux-gnu -analyzer-checker=core,unix,debug.ExprInspection %s -verify -std=c90 \
4 // RUN: -fstrict-flex-arrays=2
5 // RUN: %clang_analyze_cc1 -triple x86_64-linux-gnu -analyzer-checker=core,unix,debug.ExprInspection %s -verify -std=c99 \
6 // RUN: -fstrict-flex-arrays=2
7 // RUN: %clang_analyze_cc1 -triple x86_64-linux-gnu -analyzer-checker=core,unix,debug.ExprInspection %s -verify -std=c11 \
8 // RUN: -fstrict-flex-arrays=2
9 // RUN: %clang_analyze_cc1 -triple x86_64-linux-gnu -analyzer-checker=core,unix,debug.ExprInspection %s -verify -std=c17 \
10 // RUN: -fstrict-flex-arrays=2
12 // RUN: %clang_analyze_cc1 -triple x86_64-linux-gnu -analyzer-checker=core,unix,debug.ExprInspection %s -verify -std=c++98 -x c++ \
13 // RUN: -fstrict-flex-arrays=2
14 // RUN: %clang_analyze_cc1 -triple x86_64-linux-gnu -analyzer-checker=core,unix,debug.ExprInspection %s -verify -std=c++03 -x c++ \
15 // RUN: -fstrict-flex-arrays=2
16 // RUN: %clang_analyze_cc1 -triple x86_64-linux-gnu -analyzer-checker=core,unix,debug.ExprInspection %s -verify -std=c++11 -x c++ \
17 // RUN: -fstrict-flex-arrays=2
18 // RUN: %clang_analyze_cc1 -triple x86_64-linux-gnu -analyzer-checker=core,unix,debug.ExprInspection %s -verify -std=c++14 -x c++ \
19 // RUN: -fstrict-flex-arrays=2
20 // RUN: %clang_analyze_cc1 -triple x86_64-linux-gnu -analyzer-checker=core,unix,debug.ExprInspection %s -verify -std=c++17 -x c++ \
21 // RUN: -fstrict-flex-arrays=2
23 // By default, -fstrict-flex-arrays=0, which means that even single element arrays are considered as FAMs.
24 // RUN: %clang_analyze_cc1 -triple x86_64-linux-gnu -analyzer-checker=core,unix,debug.ExprInspection %s -verify -std=c17 \
25 // RUN: -DSINGLE_ELEMENT_FAMS
26 // RUN: %clang_analyze_cc1 -triple x86_64-linux-gnu -analyzer-checker=core,unix,debug.ExprInspection %s -verify -std=c++17 -x c++ \
27 // RUN: -DSINGLE_ELEMENT_FAMS
29 typedef __typeof(sizeof(int)) size_t;
30 size_t clang_analyzer_getExtent(void *);
31 void clang_analyzer_dump(size_t);
33 void *alloca(size_t size
);
34 void *malloc(size_t size
);
37 void test_incomplete_array_fam(void) {
44 clang_analyzer_dump(clang_analyzer_getExtent(&fam
));
45 clang_analyzer_dump(clang_analyzer_getExtent(fam
.data
));
46 // expected-warning@-2 {{4 S64b}}
47 // expected-warning@-2 {{Unknown}}
49 FAM
*p
= (FAM
*)alloca(sizeof(FAM
));
50 clang_analyzer_dump(clang_analyzer_getExtent(p
));
51 clang_analyzer_dump(clang_analyzer_getExtent(p
->data
));
52 // expected-warning@-2 {{4 U64b}}
53 // expected-warning@-2 {{Unknown}}
55 FAM
*q
= (FAM
*)malloc(sizeof(FAM
));
56 clang_analyzer_dump(clang_analyzer_getExtent(q
));
57 clang_analyzer_dump(clang_analyzer_getExtent(q
->data
));
58 // expected-warning@-2 {{4 U64b}}
59 // expected-warning@-2 {{Unknown}}
63 void test_zero_length_array_fam(void) {
70 clang_analyzer_dump(clang_analyzer_getExtent(&fam
));
71 clang_analyzer_dump(clang_analyzer_getExtent(fam
.data
));
72 // expected-warning@-2 {{4 S64b}}
73 // expected-warning@-2 {{Unknown}}
75 FAM
*p
= (FAM
*)alloca(sizeof(FAM
));
76 clang_analyzer_dump(clang_analyzer_getExtent(p
));
77 clang_analyzer_dump(clang_analyzer_getExtent(p
->data
));
78 // expected-warning@-2 {{4 U64b}}
79 // expected-warning@-2 {{Unknown}}
81 FAM
*q
= (FAM
*)malloc(sizeof(FAM
));
82 clang_analyzer_dump(clang_analyzer_getExtent(q
));
83 clang_analyzer_dump(clang_analyzer_getExtent(q
->data
));
84 // expected-warning@-2 {{4 U64b}}
85 // expected-warning@-2 {{Unknown}}
89 void test_single_element_array_possible_fam(void) {
95 #ifdef SINGLE_ELEMENT_FAMS
97 clang_analyzer_dump(clang_analyzer_getExtent(&likely_fam
));
98 clang_analyzer_dump(clang_analyzer_getExtent(likely_fam
.data
));
99 // expected-warning@-2 {{8 S64b}}
100 // expected-warning@-2 {{Unknown}}
102 FAM
*p
= (FAM
*)alloca(sizeof(FAM
));
103 clang_analyzer_dump(clang_analyzer_getExtent(p
));
104 clang_analyzer_dump(clang_analyzer_getExtent(p
->data
));
105 // expected-warning@-2 {{8 U64b}}
106 // expected-warning@-2 {{Unknown}}
108 FAM
*q
= (FAM
*)malloc(sizeof(FAM
));
109 clang_analyzer_dump(clang_analyzer_getExtent(q
));
110 clang_analyzer_dump(clang_analyzer_getExtent(q
->data
));
111 // expected-warning@-2 {{8 U64b}}
112 // expected-warning@-2 {{Unknown}}
116 clang_analyzer_dump(clang_analyzer_getExtent(&likely_fam
));
117 clang_analyzer_dump(clang_analyzer_getExtent(likely_fam
.data
));
118 // expected-warning@-2 {{8 S64b}}
119 // expected-warning@-2 {{4 S64b}}
121 FAM
*p
= (FAM
*)alloca(sizeof(FAM
));
122 clang_analyzer_dump(clang_analyzer_getExtent(p
));
123 clang_analyzer_dump(clang_analyzer_getExtent(p
->data
));
124 // expected-warning@-2 {{8 U64b}}
125 // expected-warning@-2 {{4 S64b}}
127 FAM
*q
= (FAM
*)malloc(sizeof(FAM
));
128 clang_analyzer_dump(clang_analyzer_getExtent(q
));
129 clang_analyzer_dump(clang_analyzer_getExtent(q
->data
));
130 // expected-warning@-2 {{8 U64b}}
131 // expected-warning@-2 {{4 S64b}}