1 /* PR c/50584 - No warning for passing small array to C99 static array
4 { dg-options "-Wall" } */
6 typedef __INT16_TYPE__
int16_t;
9 void fxa2 (int16_t[2]) __attribute__ ((nonnull
));
11 void fas2 (int16_t[static 2]);
13 void fvla (unsigned n
, int16_t[n
]);
14 void fvlaS (unsigned n
, int16_t[static n
]);
16 void test_array_1_dim (void)
24 fa2 (a1
); // { dg-warning "'fa2' accessing 4 bytes in a region of size 2 " }
25 fa2 (&i
); // { dg-warning "'fa2' accessing 4 bytes in a region of size 2 " }
27 fxa2 (0); // { dg-warning "\\\[-Wnonnull" }
29 fxa2 (a1
); // { dg-warning "'fxa2' accessing 4 bytes in a region of size 2 " }
30 fxa2 (&i
); // { dg-warning "'fxa2' accessing 4 bytes in a region of size 2 " }
32 fas2 (0); // { dg-warning "\\\[-Wnonnull" }
34 fas2 (a1
); // { dg-warning "'fas2' accessing 4 bytes in a region of size 2 " }
35 fas2 (&i
); // { dg-warning "'fas2' accessing 4 bytes in a region of size 2 " }
38 fvlaS (1, 0); // { dg-warning "\\\[-Wnonnull" }
41 fvla (2, a1
); // { dg-warning "'fvla' accessing 4 bytes in a region of size 2 " }
42 fvla (2, &i
); // { dg-warning "'fvla' accessing 4 bytes in a region of size 2 " }
46 void fac2 (const int16_t[2]);
47 void fxac2 (const int16_t[2]) __attribute__ ((nonnull
));
49 void facs2 (const int16_t[static 2]);
51 void fvlac (unsigned n
, const int16_t[n
]);
52 void fvlacS (unsigned n
, const int16_t[static n
]);
54 void test_const_array_1_dim (void)
62 fac2 (a1
); // { dg-warning "'fac2' reading 4 bytes from a region of size 2 " }
63 fac2 (&i
); // { dg-warning "'fac2' reading 4 bytes from a region of size 2 " }
65 fxac2 (0); // { dg-warning "\\\[-Wnonnull" }
67 fxac2 (a1
); // { dg-warning "'fxac2' reading 4 bytes from a region of size 2 " }
68 fxac2 (&i
); // { dg-warning "'fxac2' reading 4 bytes from a region of size 2 " }
70 facs2 (0); // { dg-warning "\\\[-Wnonnull" }
72 facs2 (a1
); // { dg-warning "'facs2' reading 4 bytes from a region of size 2 " }
73 facs2 (&i
); // { dg-warning "'facs2' reading 4 bytes from a region of size 2 " }
76 fvlacS (1, 0); // { dg-warning "\\\[-Wnonnull" }
79 fvlac (2, a1
); // { dg-warning "'fvlac' reading 4 bytes from a region of size 2 " }
80 fvlac (2, &i
); // { dg-warning "'fvlac' reading 4 bytes from a region of size 2 " }
84 void fca3x5 (int16_t[3][5]);
85 void fcas5x7 (int16_t[static 5][7]);
87 struct Snx5
{ int16_t a3x5
[3][5], a2x5
[2][5], a1x5
[1][5]; };
88 struct Snx7
{ int16_t a5x7
[5][7], a4x7
[4][7], a1x7
[1][7]; };
89 struct S0x7
{ int x
; int16_t a0x7
[0][7]; };
91 void test_array_2_dim (struct Snx5
*px5
, struct Snx7
*px7
, struct S0x7
*p0x7
)
93 int16_t a0x5
[0][5], a1x5
[1][5], a2x5
[2][5], a3x5
[3][5], a4x5
[4][5];
97 fca3x5 (a2x5
); // { dg-warning "'fca3x5' accessing 30 bytes in a region of size 20" }
98 fca3x5 (a1x5
); // { dg-warning "'fca3x5' accessing 30 bytes in a region of size 10" }
99 fca3x5 (a0x5
); // { dg-warning "'fca3x5' accessing 30 bytes in a region of size 0" }
102 fca3x5 (px5
->a2x5
); // { dg-warning "'fca3x5' accessing 30 bytes in a region of size 20" }
103 fca3x5 (px5
->a1x5
); // { dg-warning "'fca3x5' accessing 30 bytes in a region of size 10" "pr96346" { xfail *-*-* } }
106 int16_t (*pa2x5
)[5] = &a2x5
[0];
107 fca3x5 (pa2x5
); // { dg-warning "'fca3x5' accessing 30 bytes in a region of size 10" }
109 fca3x5 (pa2x5
); // { dg-warning "'fca3x5' accessing 30 bytes " }
112 int16_t a0x7
[0][7], a1x7
[1][7], a4x7
[4][7], a5x7
[5][7], a99x7
[99][7];
115 fcas5x7 (a4x7
); // { dg-warning "'fcas5x7' accessing 70 bytes in a region of size 56" }
116 fcas5x7 (a1x7
); // { dg-warning "'fcas5x7' accessing 70 bytes in a region of size 14" }
117 fcas5x7 (a0x7
); // { dg-warning "'fcas5x7' accessing 70 bytes in a region of size 0" }
120 fcas5x7 (px7
->a4x7
); // { dg-warning "'fcas5x7' accessing 70 bytes in a region of size 56" }
121 fcas5x7 (px7
->a1x7
); // { dg-warning "'fcas5x7' accessing 70 bytes in a region of size 14" "pr96346" { xfail *-*-* } }
123 fcas5x7 (p0x7
->a0x7
); // { dg-warning "'fcas5x7' accessing 70 bytes in a region of size 0" "pr96346" { xfail *-*-* } }