Require target lra in gcc.dg/pr108095.c
[official-gcc.git] / gcc / testsuite / c-c++-common / Warray-bounds-7.c
blob131645406dd42ff7039dc2703c83cda1bbfacadf
1 /* PR middle-end/91490 - bogus argument missing terminating nul warning
2 on strlen of a flexible array member
3 { dg-do compile }
4 { dg-options "-Wall -ftrack-macro-expansion=0" } */
6 #define INT_MAX __INT_MAX__
7 #define PTRDIFF_MAX __PTRDIFF_MAX__
8 #define SIZE_MAX __SIZE_MAX__
10 struct A0 { char n, a[0]; };
11 struct A1 { char n, a[1]; };
12 struct Ax { char n, a[]; };
14 const struct A0 a0 = { };
15 const struct A0 a0_0 = { 0 };
16 const struct A0 a0_0_ = { 0, { } };
18 const struct A0 a1 = { };
19 const struct A0 a1_0 = { 0 };
20 const struct A0 a1_0_ = { 0, { } };
22 const struct Ax ax= { };
23 const struct Ax ax_0 = { 0 };
24 const struct Ax ax_0_ = { 0, { } };
26 void sink (unsigned);
28 #define T(x) sink (__builtin_strlen (x))
30 void test_zero_length_array (void)
32 T (a0.a); // { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" }
33 T (a0.a - 1); // { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" }
34 T (a0.a + 1); // { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" }
35 T (a0.a + 9); // { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" }
36 T (a0.a + INT_MAX); // { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" }
37 T (a0.a + PTRDIFF_MAX); // { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" }
38 T (a0.a + SIZE_MAX); // { dg-warning "\\\[-Warray-bounds" }
40 T (a0_0.a); // { dg-warning "\\\[-Warray-bounds" }
41 T (a0_0.a - 1); // { dg-warning "\\\[-Warray-bounds" }
42 T (a0_0.a + 1); // { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" }
43 T (a0_0.a + 9); // { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" }
44 T (a0_0.a + INT_MAX); // { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" }
45 T (a0_0.a + PTRDIFF_MAX); // { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" }
46 T (a0_0.a + SIZE_MAX); // { dg-warning "\\\[-Warray-bounds" }
48 T (a0_0_.a); // { dg-warning "\\\[-Warray-bounds" }
49 T (a0_0_.a - 1); // { dg-warning "\\\[-Warray-bounds" }
50 T (a0_0_.a + 1); // { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" }
51 T (a0_0_.a + 9); // { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" }
52 T (a0_0_.a + INT_MAX); // { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" }
53 T (a0_0_.a + PTRDIFF_MAX); // { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" }
54 T (a0_0_.a + SIZE_MAX); // { dg-warning "\\\[-Warray-bounds" }
57 void test_one_element_array (void)
59 T (a1.a - 1); // { dg-warning "\\\[-Warray-bounds" }
60 T (a1.a + 1); // { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" }
61 T (a1.a + 9); // { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" }
62 T (a1.a + INT_MAX); // { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" }
63 T (a1.a + PTRDIFF_MAX); // { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" }
64 T (a1.a + SIZE_MAX); // { dg-warning "\\\[-Warray-bounds" }
66 T (a1_0.a - 1); // { dg-warning "\\\[-Warray-bounds" }
67 T (a1_0.a + 1); // { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" }
68 T (a1_0.a + 9); // { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" }
69 T (a1_0.a + INT_MAX); // { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" }
70 T (a1_0.a + PTRDIFF_MAX); // { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" }
71 T (a1_0.a + SIZE_MAX); // { dg-warning "\\\[-Warray-bounds" }
73 T (a1_0_.a - 1); // { dg-warning "\\\[-Warray-bounds" }
74 T (a1_0_.a + 1); // { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" }
75 T (a1_0_.a + 9); // { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" }
76 T (a1_0_.a + INT_MAX); // { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" }
77 T (a1_0_.a + PTRDIFF_MAX); // { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" }
78 T (a1_0_.a + SIZE_MAX); // { dg-warning "\\\[-Warray-bounds" }
81 void test_flexible_array_member (void)
83 T (ax.a); // { dg-warning "\\\[-Warray-bounds" }
84 T (ax.a - 1); // { dg-warning "\\\[-Warray-bounds" }
85 T (ax.a + 1); // { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" }
86 T (ax.a + 9); // { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" }
87 T (ax.a + INT_MAX); // { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" }
88 T (ax.a + PTRDIFF_MAX); // { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" }
89 T (ax.a + SIZE_MAX); // { dg-warning "\\\[-Warray-bounds" }
91 T (ax_0.a); // { dg-warning "\\\[-Warray-bounds" }
92 T (ax_0.a - 1); // { dg-warning "\\\[-Warray-bounds" }
93 T (ax_0.a + 1); // { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" }
94 T (ax_0.a + 9); // { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" }
95 T (ax_0.a + INT_MAX); // { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" }
96 T (ax_0.a + PTRDIFF_MAX); // { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" }
97 T (ax_0.a + SIZE_MAX); // { dg-warning "\\\[-Warray-bounds" }
99 T (ax_0_.a); // { dg-warning "\\\[-Warray-bounds" }
100 T (ax_0_.a - 1); // { dg-warning "\\\[-Warray-bounds" }
101 T (ax_0_.a + 1); // { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" }
102 T (ax_0_.a + 9); // { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" }
103 T (ax_0_.a + INT_MAX); // { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" }
104 T (ax_0_.a + PTRDIFF_MAX); // { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" }
105 T (ax_0_.a + SIZE_MAX); // { dg-warning "\\\[-Warray-bounds" }