Require target lra in gcc.dg/pr108095.c
[official-gcc.git] / gcc / testsuite / gcc.dg / Wstringop-overflow-40.c
blob386c92dc7a813db66423c7d2083e2a75798b0987
1 /* PR c/50584 - No warning for passing small array to C99 static array
2 declarator
3 { dg-do compile }
4 { dg-options "-Wall" } */
6 typedef __INT16_TYPE__ int16_t;
8 void fa2 (int16_t[2]);
9 void fxa2 (int16_t[2]) __attribute__ ((nonnull));
11 void fas2 (int16_t[static 2]);
13 void fvla (unsigned n, int16_t[n]);
15 void test_array_1_dim (void)
17 int16_t a1[1];
18 int16_t a2[2];
19 int16_t i;
21 fa2 (0);
22 fa2 (a2);
23 fa2 (a1); // { dg-warning "'fa2' accessing 4 bytes in a region of size 2 " }
24 fa2 (&i); // { dg-warning "'fa2' accessing 4 bytes in a region of size 2 " }
26 fxa2 (0); // { dg-warning "\\\[-Wnonnull" }
27 fxa2 (a2);
28 fxa2 (a1); // { dg-warning "'fxa2' accessing 4 bytes in a region of size 2 " }
29 fxa2 (&i); // { dg-warning "'fxa2' accessing 4 bytes in a region of size 2 " }
31 fas2 (0); // { dg-warning "\\\[-Wnonnull" }
32 fas2 (a2);
33 fas2 (a1); // { dg-warning "'fas2' accessing 4 bytes in a region of size 2 " }
34 fas2 (&i); // { dg-warning "'fas2' accessing 4 bytes in a region of size 2 " }
36 fvla (1, 0); // { dg-warning "\\\[-Wnonnull" }
37 fvla (1, &i);
38 fvla (2, a2);
39 fvla (2, a1); // { dg-warning "'fvla' accessing 4 bytes in a region of size 2 " }
40 fvla (2, &i); // { dg-warning "'fvla' accessing 4 bytes in a region of size 2 " }
44 void fac2 (const int16_t[2]);
45 void fxac2 (const int16_t[2]) __attribute__ ((nonnull));
47 void facs2 (const int16_t[static 2]);
49 void fvlac (unsigned n, const int16_t[n]);
51 void test_const_array_1_dim (void)
53 int16_t a1[1];
54 int16_t a2[2];
55 int16_t i;
57 fac2 (0);
58 fac2 (a2);
59 fac2 (a1); // { dg-warning "'fac2' reading 4 bytes from a region of size 2 " }
60 fac2 (&i); // { dg-warning "'fac2' reading 4 bytes from a region of size 2 " }
62 fxac2 (0); // { dg-warning "\\\[-Wnonnull" }
63 fxac2 (a2);
64 fxac2 (a1); // { dg-warning "'fxac2' reading 4 bytes from a region of size 2 " }
65 fxac2 (&i); // { dg-warning "'fxac2' reading 4 bytes from a region of size 2 " }
67 facs2 (0); // { dg-warning "\\\[-Wnonnull" }
68 facs2 (a2);
69 facs2 (a1); // { dg-warning "'facs2' reading 4 bytes from a region of size 2 " }
70 facs2 (&i); // { dg-warning "'facs2' reading 4 bytes from a region of size 2 " }
72 fvlac (1, 0); // { dg-warning "\\\[-Wnonnull" }
73 fvlac (1, &i);
74 fvlac (2, a2);
75 fvlac (2, a1); // { dg-warning "'fvlac' reading 4 bytes from a region of size 2 " }
76 fvlac (2, &i); // { dg-warning "'fvlac' reading 4 bytes from a region of size 2 " }
80 void fca3x5 (int16_t[3][5]);
81 void fcas5x7 (int16_t[static 5][7]);
83 struct Snx5 { int16_t a3x5[3][5], a2x5[2][5], a1x5[1][5]; };
84 struct Snx7 { int16_t a5x7[5][7], a4x7[4][7], a1x7[1][7]; };
85 struct S0x7 { int x; int16_t a0x7[0][7]; };
87 void test_array_2_dim (struct Snx5 *px5, struct Snx7 *px7, struct S0x7 *p0x7)
89 int16_t a0x5[0][5], a1x5[1][5], a2x5[2][5], a3x5[3][5], a4x5[4][5];
91 fca3x5 (a3x5);
92 fca3x5 (a4x5);
93 fca3x5 (a2x5); // { dg-warning "'fca3x5' accessing 30 bytes in a region of size 20" }
94 fca3x5 (a1x5); // { dg-warning "'fca3x5' accessing 30 bytes in a region of size 10" }
95 fca3x5 (a0x5); // { dg-warning "'fca3x5' accessing 30 bytes in a region of size 0" }
97 fca3x5 (px5->a3x5);
98 fca3x5 (px5->a2x5); // { dg-warning "'fca3x5' accessing 30 bytes in a region of size 20" }
99 fca3x5 (px5->a1x5); // { dg-warning "'fca3x5' accessing 30 bytes in a region of size 10" "pr96346" { xfail *-*-* } }
102 int16_t (*pa2x5)[5] = &a2x5[0];
103 fca3x5 (pa2x5); // { dg-warning "'fca3x5' accessing 30 bytes in a region of size 10" }
104 ++pa2x5;
105 fca3x5 (pa2x5); // { dg-warning "'fca3x5' accessing 30 bytes " }
108 int16_t a0x7[0][7], a1x7[1][7], a4x7[4][7], a5x7[5][7], a99x7[99][7];
109 fcas5x7 (a99x7);
110 fcas5x7 (a5x7);
111 fcas5x7 (a4x7); // { dg-warning "'fcas5x7' accessing 70 bytes in a region of size 56" }
112 fcas5x7 (a1x7); // { dg-warning "'fcas5x7' accessing 70 bytes in a region of size 14" }
113 fcas5x7 (a0x7); // { dg-warning "'fcas5x7' accessing 70 bytes in a region of size 0" }
115 fcas5x7 (px7->a5x7);
116 fcas5x7 (px7->a4x7); // { dg-warning "'fcas5x7' accessing 70 bytes in a region of size 56" }
117 fcas5x7 (px7->a1x7); // { dg-warning "'fcas5x7' accessing 70 bytes in a region of size 14" "pr96346" { xfail *-*-* } }
119 fcas5x7 (p0x7->a0x7); // { dg-warning "'fcas5x7' accessing 70 bytes in a region of size 0" "pr96346" { xfail *-*-* } }