libcpp, c, middle-end: Optimize initializers using #embed in C
[official-gcc.git] / gcc / testsuite / gcc.dg / Wstringop-overflow-21.c
blob4cd3c1b4f624e474bb27b3c30e6a748422a5013e
1 /* PR middle-end/92312 - bogus -Wstringop-overflow storing into a trailing
2 array backed by larger buffer
3 { dg-do compile }
4 { dg-options "-O2 -Wall -Wno-array-bounds" } */
6 struct S0 { char a, b[0]; };
8 void sink (void*);
10 void test_memset_zero_length (void)
12 char a[3];
13 struct S0 *p = (struct S0*)a;
14 p->a = 0;
15 __builtin_memset (p->b, 0, 2);
16 sink (p);
18 __builtin_memset (p->b, 0, 3); // { dg-warning "\\\[-Wstringop-overflow" }
19 sink (p);
22 void test_store_zero_length (int i)
24 char a[3];
25 struct S0 *p = (struct S0*)a;
26 p->a = 0; // { dg-warning "\\\[-Wstringop-overflow" "pr102706" { target { vect_slp_v4qi_store_align } } }
27 p->b[0] = 0;
28 p->b[1] = 1; // { dg-bogus "\\\[-Wstringop-overflow" }
29 p->b[2] = 2; // { dg-warning "\\\[-Wstringop-overflow" "pr102706" { xfail { vect_slp_v4qi_store_align } } }
30 p->b[i] = 2;
31 sink (p);
35 struct Sx { char a, b[]; };
37 void test_memset_flexarray (int i)
39 char a[3];
40 struct Sx *p = (struct Sx*)a;
41 p->a = 0;
42 __builtin_memset (p->b, 0, 2);
43 sink (p);
45 __builtin_memset (p->b, 0, 3); // { dg-warning "\\\[-Wstringop-overflow" }
46 sink (p);
49 void test_store_flexarray (int i)
51 char a[3];
52 struct Sx *p = (struct Sx*)a;
53 p->a = 0; // { dg-warning "\\\[-Wstringop-overflow" "pr102706" { target { vect_slp_v4qi_store_align } } }
54 p->b[0] = 0;
55 p->b[1] = 1; // { dg-bogus "\\\[-Wstringop-overflow" }
56 p->b[2] = 1; // { dg-warning "\\\[-Wstringop-overflow" "pr102706" { xfail { vect_slp_v4qi_store_align } } }
57 p->b[i] = 2;
58 sink (p);