libcpp, c, middle-end: Optimize initializers using #embed in C
[official-gcc.git] / gcc / testsuite / gcc.dg / Warray-bounds-69.c
blob80503f8d217e7e173893f5f7619ece75d8739da9
1 /* Verify that storing a bigger vector into smaller space is diagnosed.
2 { dg-do compile }
3 { dg-options "-O2 -Warray-bounds -Wno-stringop-overflow" } */
5 typedef __INT16_TYPE__ int16_t;
6 typedef __attribute__ ((__vector_size__ (32))) char C32;
8 typedef __attribute__ ((__vector_size__ (64))) int16_t I16_64;
10 void sink (void*);
13 void nowarn_c32 (char c)
15 extern char nowarn_a32[32];
17 void *p = nowarn_a32;
18 *(C32*)p = (C32){ c };
19 sink (p);
21 char a32[32];
22 p = a32;
23 *(C32*)p = (C32){ c };
24 sink (p);
27 /* The invalid stores below are diagnosed by -Warray-bounds only
28 because it doesn't use compute_objsize(). If/when that changes
29 the function might need adjusting to avoid the hack put in place
30 to avoid false positives due to vectorization. */
32 void warn_c32 (char c)
34 extern char warn_a32[32]; // { dg-message "'warn_a32'" "note" }
36 void *p = warn_a32 + 1;
37 *(C32*)p = (C32){ c }; // { dg-warning "\\\[-Warray-bounds" }
39 /* Verify a local variable too. */
40 char a32[32]; // { dg-message "'a32'" }
41 p = a32 + 1;
42 *(C32*)p = (C32){ c }; // { dg-warning "\\\[-Warray-bounds" }
43 sink (p);
47 void nowarn_i16_64 (int16_t i)
49 extern char nowarn_a64[64];
51 void *p = nowarn_a64;
52 I16_64 *q = (I16_64*)p;
53 *q = (I16_64){ i };
55 char a64[64];
56 q = (I16_64*)a64;
57 *q = (I16_64){ i };
58 sink (q);
61 void warn_i16_64 (int16_t i)
63 extern char warn_a64[64]; // { dg-message "'warn_a64'" }
65 void *p = warn_a64 + 1;
66 I16_64 *q = (I16_64*)p;
67 *q = (I16_64){ i }; // { dg-warning "\\\[-Warray-bounds" }
69 char a64[64]; // { dg-message "'a64'" }
70 p = a64 + 1;
71 q = (I16_64*)p;
72 *q = (I16_64){ i }; // { dg-warning "\\\[-Warray-bounds" }
73 sink (p);