| 1 |
/* PR c/50584 - No warning for passing small array to C99 static array |
| 2 |
declarator |
| 3 |
{ dg-do compile } |
| 4 |
{ dg-options "-Wall -Warray-parameter=1" } */ |
| 5 |
|
| 6 |
/* Verify that at level 1 mismatches in the bounds of ordinary array |
| 7 |
parameters don't trigger -Warray-parameter. */ |
| 8 |
void fax (int[]); |
| 9 |
void fax (int[0]); |
| 10 |
void fax (int[1]); |
| 11 |
void fax (int[2]); |
| 12 |
void fax (int[3]); |
| 13 |
|
| 14 |
/* Same as above but starting with an array with a specified bound. */ |
| 15 |
void gax (int[3]); |
| 16 |
void gax (int[2]); |
| 17 |
void gax (int[1]); |
| 18 |
void gax (int[0]); |
| 19 |
void gax (int[]); |
| 20 |
|
| 21 |
/* Same for multidimensional arrays. */ |
| 22 |
void fax_y (int[][3]); |
| 23 |
void fax_y (int[0][3]); |
| 24 |
void fax_y (int[1][3]); |
| 25 |
void fax_y (int[2][3]); |
| 26 |
void fax_y (int[3][3]); |
| 27 |
|
| 28 |
/* Same as above but starting with an array with a specified bound. */ |
| 29 |
void gax_y (int[3][5]); |
| 30 |
void gax_y (int[2][5]); |
| 31 |
void gax_y (int[1][5]); |
| 32 |
void gax_y (int[0][5]); |
| 33 |
void gax_y (int[][5]); |
| 34 |
|
| 35 |
/* Exercise VLAs with a mismatch in the bound for an ordinary array. */ |
| 36 |
void fvlax_y (int n, int[][n]); |
| 37 |
void fvlax_y (int n, int[0][n]); |
| 38 |
void fvlax_y (int n, int[1][n]); |
| 39 |
void fvlax_y (int n, int[2][n]); |
| 40 |
void fvlax_y (int n, int[3][n]); |
| 41 |
|
| 42 |
void fvlaxn_y (int n, int[][n]); |
| 43 |
void fvlaxn_y (int n, int[0][n]); |
| 44 |
void fvlaxn_y (int n, int[1][n]); |
| 45 |
void fvlaxn_y (int n, int[2][n]); |
| 46 |
void fvlaxn_y (int n, int[3][n]); |
| 47 |
|
| 48 |
void fvlaxx_y (int[][*]); |
| 49 |
void fvlaxx_y (int[0][*]); |
| 50 |
void fvlaxx_y (int[1][*]); |
| 51 |
void fvlaxx_y (int[2][*]); |
| 52 |
void fvlaxx_y (int[3][*]); |
| 53 |
|
| 54 |
/* Verify that mismatches in the bounds of array parameters declared |
| 55 |
static do trigger -Warray-parameter. */ |
| 56 |
void fas1 (int[static 1]); // { dg-message "previously declared as 'int\\\[static 1]'" } |
| 57 |
void fas1 (int[static 2]); // { dg-warning "\\\[-Warray-parameter=" } |
| 58 |
|
| 59 |
|
| 60 |
/* Also verify that -Warray-bounds doesn't trigger for ordinary array |
| 61 |
parameters... */ |
| 62 |
#pragma GCC optimize ("2") |
| 63 |
|
| 64 |
__attribute__ ((noipa)) void |
| 65 |
gca3 (char a[3]) |
| 66 |
{ |
| 67 |
a[0] = 0; a[1] = 1; a[2] = 2; a[3] = 3; |
| 68 |
} |
| 69 |
|
| 70 |
__attribute__ ((noipa)) void |
| 71 |
gia3 (int a[3]) |
| 72 |
{ |
| 73 |
a[0] = 0; a[1] = 1; a[2] = 2; a[3] = 3; |
| 74 |
} |
| 75 |
|
| 76 |
/* ...but does for static arrays. */ |
| 77 |
__attribute__ ((noipa)) void |
| 78 |
gcas3 (char a[static 3]) |
| 79 |
{ |
| 80 |
a[0] = 0; a[1] = 1; a[2] = 2; // { dg-warning "\\\[-Wstringop-overflow" "pr102706" { target { vect_slp_v4qi_store_unalign } } } |
| 81 |
a[3] = 3; // { dg-warning "\\\[-Warray-bounds" } |
| 82 |
} |
| 83 |
|
| 84 |
__attribute__ ((noipa)) void |
| 85 |
gias3 (int a[static 3]) |
| 86 |
{ |
| 87 |
a[0] = 0; a[1] = 1; a[2] = 2; |
| 88 |
a[3] = 3; // { dg-warning "\\\[-Warray-bounds" } |
| 89 |
} |