| 1 |
/* PR c/50584 - No warning for passing small array to C99 static array |
| 2 |
declarator |
| 3 |
Verify warnings for multidimensional arrays, including mismatches |
| 4 |
in bounds of arrays of VLAs. (Mismatches in variable bounds are |
| 5 |
diagnosed by -Wvla-parameter.) |
| 6 |
{ dg-do compile } |
| 7 |
{ dg-options "-Wall -Warray-parameter=2" } */ |
| 8 |
|
| 9 |
// Verify that equivalent forms don't tigger a warning. |
| 10 |
|
| 11 |
typedef int IA1[1]; |
| 12 |
typedef int IA1x_[][1]; |
| 13 |
typedef int IA1x0[0][1]; |
| 14 |
|
| 15 |
void fia_x1 (int[][1]); |
| 16 |
void fia_x1 (IA1[0]); |
| 17 |
void fia_x1 (IA1x_); |
| 18 |
void fia_x1 (IA1x0); |
| 19 |
void fia_x1 (int[0][1]); |
| 20 |
void fia_x1 (int[static 0][1]); |
| 21 |
|
| 22 |
// Same as above one more time. |
| 23 |
void fia_x1 (int[][1]); |
| 24 |
void fia_x1 (IA1[0]); |
| 25 |
void fia_x1 (IA1x_); |
| 26 |
void fia_x1 (IA1x0); |
| 27 |
void fia_x1 (int[0][1]); |
| 28 |
void fia_x1 (int[static 0][1]); |
| 29 |
|
| 30 |
|
| 31 |
void fia1x1 (int[1][1]); |
| 32 |
void fia1x1 (int[1][1]); |
| 33 |
void fia1x1 (int[static 1][1]); |
| 34 |
|
| 35 |
void fia2x1 (int[2][1]); |
| 36 |
void fia2x1 (int[2][1]); |
| 37 |
void fia2x1 (int[static 2][1]); |
| 38 |
|
| 39 |
void fia1x2 (int[1][2]); |
| 40 |
void fia1x2 (int[1][2]); |
| 41 |
void fia1x2 (int[static 1][2]); |
| 42 |
|
| 43 |
void fia1x1_2x1 (int[1][1]); // { dg-message "previously declared as 'int\\\[1]\\\[1]'" } |
| 44 |
void fia1x1_2x1 (int[2][1]); // { dg-warning "\\\[-Warray-parameter" } |
| 45 |
void fia1x1_2x1 (int[static 1][1]); |
| 46 |
void fia1x1_2x1 (int[static 2][1]); // { dg-warning "\\\[-Warray-parameter" } |
| 47 |
|
| 48 |
|
| 49 |
void fia2x1_1x1 (int[2][1]); // { dg-message "previously declared as 'int\\\[2]\\\[1]'" } |
| 50 |
void fia2x1_1x1 (int[1][1]); // { dg-warning "\\\[-Warray-parameter" } |
| 51 |
void fia2x1_1x1 (int[2][1]); |
| 52 |
void fia2x1_1x1 (int[static 1][1]); // { dg-warning "\\\[-Warray-parameter" } |
| 53 |
void fia2x1_1x1 (int[static 2][1]); |
| 54 |
|
| 55 |
|
| 56 |
extern int n1, n2; |
| 57 |
|
| 58 |
void fca_xn1 (char[][n1]); |
| 59 |
void fca_xn1 (char[0][n1]); |
| 60 |
void fca_xn1 (char[static 0][n1]); |
| 61 |
|
| 62 |
void fca1xn1_2xn1 (char[1][n1]); |
| 63 |
void fca1xn1_2xn1 (char[2][n1]); // { dg-warning "\\\[-Warray-parameter" } |
| 64 |
void fca1xn1_2xn1 (char[1][n1]); |
| 65 |
void fca1xn1_2xn1 (char[static 1][n1]); |
| 66 |
void fca1xn1_2xn1 (char[static 2][n1]); // { dg-warning "\\\[-Warray-parameter" } |
| 67 |
|
| 68 |
|
| 69 |
/* Exercise VLAs with a mismatch in the bound for an ordinary array. */ |
| 70 |
void fvlax_y (int n, int[][n]); |
| 71 |
void fvlax_y (int n, int[0][n]); |
| 72 |
void fvlax_y (int n, int[1][n]); // { dg-warning "argument 2 of type 'int\\\[1]\\\[n]' with mismatched bound" } |
| 73 |
void fvlax_y (int n, int[2][n]); // { dg-warning "argument 2 of type 'int\\\[2]\\\[n]' with mismatched bound" } |
| 74 |
void fvlax_y (int n, int[3][n]); // { dg-warning "argument 2 of type 'int\\\[3]\\\[n]' with mismatched bound" } |
| 75 |
|
| 76 |
void fvlaxn_y (int n, int[][n]); |
| 77 |
void fvlaxn_y (int n, int[0][n]); |
| 78 |
void fvlaxn_y (int n, int[1][n]); // { dg-warning "\\\[-Warray-parameter" } |
| 79 |
void fvlaxn_y (int n, int[2][n]); // { dg-warning "\\\[-Warray-parameter" } |
| 80 |
void fvlaxn_y (int n, int[3][n]); // { dg-warning "\\\[-Warray-parameter" } |
| 81 |
|
| 82 |
void fvlaxx_y (int[][*]); |
| 83 |
void fvlaxx_y (int[0][*]); |
| 84 |
void fvlaxx_y (int[1][*]); // { dg-warning "\\\[-Warray-parameter" } |
| 85 |
void fvlaxx_y (int[2][*]); // { dg-warning "\\\[-Warray-parameter" } |
| 86 |
void fvlaxx_y (int[3][*]); // { dg-warning "\\\[-Warray-parameter" } |
| 87 |
|
| 88 |
|
| 89 |
// Verify an array of pointers to an array of function pointers. |
| 90 |
|
| 91 |
void ffpa7_5 (void (* (* (* [7])[5])(void))(void)); |
| 92 |
// { dg-message "previously declared as 'void \\\(\\\* ?\\\(\\\* ?\\\(\\\*\\\[7]\\\)\\\[5]\\\)\\\(void\\\)\\\)\\\(void\\\)'" "note" { target *-*-* } .-1 } |
| 93 |
void ffpa7_5 (void (* (* (* [6])[5])(void))(void)); |
| 94 |
// { dg-warning "argument 1 of type 'void \\\(\\\* ?\\\(\\\* ?\\\(\\\*\\\[6]\\\)\\\[5]\\\)\\\(void\\\)\\\)\\\(void\\\)' with mismatched bound" "" { target *-*-* } .-1 } |
| 95 |
void ffpa7_5 (void (* (* (* [])[5])(void))(void)); |
| 96 |
// { dg-warning "argument 1 of type 'void \\\(\\\* ?\\\(\\\* ?\\\(\\\*\\\[]\\\)\\\[5]\\\)\\\(void\\\)\\\)\\\(void\\\)' with mismatched bound" "" { target *-*-* } .-1 } |
| 97 |
void ffpa7_5 (void (* (* (* (*))[5])(void))(void)); |
| 98 |
// { dg-warning "argument 1 of type 'void \\\(\\\* ?\\\(\\\* ?\\\(\\\*\\\*\\\)\\\[5]\\\)\\\(void\\\)\\\)\\\(void\\\)' declared as a pointer" "" { target *-*-* } .-1 } |
| 99 |
|
| 100 |
// Same as above but with array of pointers to a VLA of function pointers. |
| 101 |
void ffpa7_n1 (void (* (* (* [7])[n1])(void))(void)); |
| 102 |
// { dg-message "previously declared as 'void \\\(\\\* ?\\\(\\\* ?\\\(\\\*\\\[7]\\\)\\\[n1]\\\)\\\(void\\\)\\\)\\\(void\\\)'" "note" { target *-*-* } .-1 } |
| 103 |
void ffpa7_n1 (void (* (* (* [8])[n1])(void))(void)); |
| 104 |
// { dg-warning "argument 1 of type 'void \\\(\\\* ?\\\(\\\* ?\\\(\\\*\\\[8]\\\)\\\[n1]\\\)\\\(void\\\)\\\)\\\(void\\\)' with mismatched bound" "" { target *-*-* } .-1 } |
| 105 |
|
| 106 |
void ffpa9_x (void (* (* (* [9])[*])(void))(void)); |
| 107 |
// { dg-message "previously declared as 'void \\\(\\\* ?\\\(\\\* ?\\\(\\\*\\\[9]\\\)\\\[\\\*]\\\)\\\(void\\\)\\\)\\\(void\\\)'" "pr?????" { target *-*-* } .-1 } |
| 108 |
void ffpa9_x (void (* (* (* [8])[*])(void))(void)); |
| 109 |
// { dg-warning "argument 1 of type 'void \\\(\\\* ?\\\(\\\* ?\\\(\\\*\\\[8]\\\)\\\[\\\*]\\\)\\\(void\\\)\\\)\\\(void\\\)' with mismatched bound" "pr?????" { target *-*-* } .-1 } |
| 110 |
|
| 111 |
/* Verify a three-dimensional array of pointers to two-dimensional arrays |
| 112 |
of pointers to function pointers. */ |
| 113 |
|
| 114 |
void ffpa7_5_3 (void (* (* (* (* [7])[5])[3])(void))(void)); |
| 115 |
// { dg-message "previously declared as 'void ?\\\(\\\* ?\\\(\\\* ?\\\(\\\* ?\\\(\\\* ?\\\[7]\\\)\\\[5]\\\)\\\[3]\\\)\\\(void\\\)\\\)\\\(void\\\)'" "note" { target *-*-* } .-1 } |
| 116 |
void ffpa7_5_3 (void (* (* (* (* [1])[5])[3])(void))(void)); |
| 117 |
// { dg-warning "argument 1 of type 'void ?\\\(\\\* ?\\\(\\\* ?\\\(\\\* ?\\\(\\\* ?\\\[1]\\\)\\\[5]\\\)\\\[3]\\\)\\\(void\\\)\\\)\\\(void\\\)' with mismatched bound" "" { target *-*-* } .-1 } |