1 /* PR middle-end/92815 - spurious -Wstringop-overflow writing into
2 a flexible array of an extern struct
3 { dg-do compile }
4 { dg-options "-Wall -fdump-tree-optimized" }
5 { dg-require-effective-target large_initializer } */
6
7 #define PTRDIFF_MAX __PTRDIFF_MAX__
8
9 typedef __SIZE_TYPE__ size_t;
10
11 #define bos0(expr) __builtin_object_size (expr, 0)
12 #define bos1(expr) __builtin_object_size (expr, 1)
13 #define bos2(expr) __builtin_object_size (expr, 2)
14 #define bos3(expr) __builtin_object_size (expr, 3)
15
16 void fail (const char*, ...);
17
18 #define A(x, n01, n23) \
19 ((bos0 (&x) == n01 ? (void)0 : fail (#x, __LINE__, bos0 (&x), n01)), \
20 (bos1 (&x) == n01 ? (void)0 : fail (#x, __LINE__, bos1 (&x), n01)), \
21 (bos2 (&x) == n23 ? (void)0 : fail (#x, __LINE__, bos2 (&x), n23)), \
22 (bos3 (&x) == n23 ? (void)0 : fail (#x, __LINE__, bos3 (&x), n23)))
23
24 struct Ax_m3 { char a[PTRDIFF_MAX - 3], ax[]; };
25
26 struct Ax_m3 xm3_0 = { { 0 } };
27 struct Ax_m3 xm3_1 = { { 0 }, { 1 } };
28 struct Ax_m3 xm3_2 = { { 0 }, { 1, 2 } };
29 struct Ax_m3 xm3_3 = { { 0 }, { 1, 2, 3 } };
30 struct Ax_m3 xm3_4 = { { 0 }, { 1, 2, 3, 3 } }; // { dg-error "too large" }
31
test_axm3(void)32 void test_axm3 (void)
33 {
34 A (xm3_0, sizeof xm3_0, sizeof xm3_0);
35 A (xm3_1, sizeof xm3_1 + 1, sizeof xm3_1 + 1);
36 A (xm3_2, sizeof xm3_2 + 2, sizeof xm3_2 + 2);
37 A (xm3_3, (size_t)-1, 0); // expect failure
38 A (xm3_4, (size_t)-1, 0); // expect failure
39 }
40
41
42 struct Ax_mx { char a[PTRDIFF_MAX], ax[]; };
43 struct Ax_mx xmx_0 = { { 0 } };
44 struct Ax_mx xmx_1 = { { 0 }, { 1 } }; // { dg-error "too large" }
45 extern struct Ax_mx xmx_x;
46
test_axmx(void)47 void test_axmx (void)
48 {
49 A (xmx_0, (size_t)-1, 0); // expect failure
50 A (xmx_1, (size_t)-1, 0); // expect failure
51 A (xmx_x, (size_t)-1, 0); // expect failure
52 }
53