| 1 |
/* PR c/50584 - No warning for passing small array to C99 static array |
| 2 |
declarator |
| 3 |
{ dg-do compile } |
| 4 |
{ dg-options "-Wall" } */ |
| 5 |
|
| 6 |
typedef __INT16_TYPE__ int16_t; |
| 7 |
|
| 8 |
void fa2 (int16_t[2]); |
| 9 |
void fxa2 (int16_t[2]) __attribute__ ((nonnull)); |
| 10 |
|
| 11 |
void fas2 (int16_t[static 2]); |
| 12 |
|
| 13 |
void fvla (unsigned n, int16_t[n]); |
| 14 |
void fvlaS (unsigned n, int16_t[static n]); |
| 15 |
|
| 16 |
void test_array_1_dim (void) |
| 17 |
{ |
| 18 |
int16_t a1[1]; |
| 19 |
int16_t a2[2]; |
| 20 |
int16_t i; |
| 21 |
|
| 22 |
fa2 (0); |
| 23 |
fa2 (a2); |
| 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 " } |
| 26 |
|
| 27 |
fxa2 (0); // { dg-warning "\\\[-Wnonnull" } |
| 28 |
fxa2 (a2); |
| 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 " } |
| 31 |
|
| 32 |
fas2 (0); // { dg-warning "\\\[-Wnonnull" } |
| 33 |
fas2 (a2); |
| 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 " } |
| 36 |
|
| 37 |
fvla (1, 0); |
| 38 |
fvlaS (1, 0); // { dg-warning "\\\[-Wnonnull" } |
| 39 |
fvla (1, &i); |
| 40 |
fvla (2, a2); |
| 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 " } |
| 43 |
} |
| 44 |
|
| 45 |
|
| 46 |
void fac2 (const int16_t[2]); |
| 47 |
void fxac2 (const int16_t[2]) __attribute__ ((nonnull)); |
| 48 |
|
| 49 |
void facs2 (const int16_t[static 2]); |
| 50 |
|
| 51 |
void fvlac (unsigned n, const int16_t[n]); |
| 52 |
void fvlacS (unsigned n, const int16_t[static n]); |
| 53 |
|
| 54 |
void test_const_array_1_dim (void) |
| 55 |
{ |
| 56 |
int16_t a1[1]; |
| 57 |
int16_t a2[2]; |
| 58 |
int16_t i; |
| 59 |
|
| 60 |
fac2 (0); |
| 61 |
fac2 (a2); |
| 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 " } |
| 64 |
|
| 65 |
fxac2 (0); // { dg-warning "\\\[-Wnonnull" } |
| 66 |
fxac2 (a2); |
| 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 " } |
| 69 |
|
| 70 |
facs2 (0); // { dg-warning "\\\[-Wnonnull" } |
| 71 |
facs2 (a2); |
| 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 " } |
| 74 |
|
| 75 |
fvlac (1, 0); |
| 76 |
fvlacS (1, 0); // { dg-warning "\\\[-Wnonnull" } |
| 77 |
fvlac (1, &i); |
| 78 |
fvlac (2, a2); |
| 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 " } |
| 81 |
} |
| 82 |
|
| 83 |
|
| 84 |
void fca3x5 (int16_t[3][5]); |
| 85 |
void fcas5x7 (int16_t[static 5][7]); |
| 86 |
|
| 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]; }; |
| 90 |
|
| 91 |
void test_array_2_dim (struct Snx5 *px5, struct Snx7 *px7, struct S0x7 *p0x7) |
| 92 |
{ |
| 93 |
int16_t a0x5[0][5], a1x5[1][5], a2x5[2][5], a3x5[3][5], a4x5[4][5]; |
| 94 |
|
| 95 |
fca3x5 (a3x5); |
| 96 |
fca3x5 (a4x5); |
| 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" } |
| 100 |
|
| 101 |
fca3x5 (px5->a3x5); |
| 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 *-*-* } } |
| 104 |
|
| 105 |
{ |
| 106 |
int16_t (*pa2x5)[5] = &a2x5[0]; |
| 107 |
fca3x5 (pa2x5); // { dg-warning "'fca3x5' accessing 30 bytes in a region of size 10" } |
| 108 |
++pa2x5; |
| 109 |
fca3x5 (pa2x5); // { dg-warning "'fca3x5' accessing 30 bytes " } |
| 110 |
} |
| 111 |
|
| 112 |
int16_t a0x7[0][7], a1x7[1][7], a4x7[4][7], a5x7[5][7], a99x7[99][7]; |
| 113 |
fcas5x7 (a99x7); |
| 114 |
fcas5x7 (a5x7); |
| 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" } |
| 118 |
|
| 119 |
fcas5x7 (px7->a5x7); |
| 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 *-*-* } } |
| 122 |
|
| 123 |
fcas5x7 (p0x7->a0x7); // { dg-warning "'fcas5x7' accessing 70 bytes in a region of size 0" "pr96346" { xfail *-*-* } } |
| 124 |
} |