aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/Warray-parameter-4.c
blob: b702d730a13ec7a7114285e242f95d78fdb9d001 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/* PR c/50584 - No warning for passing small array to C99 static array
   declarator
   Verify warnings for multidimensional arrays, including mismatches
   in bounds of arrays of VLAs.  (Mismatches in variable bounds are
   diagnosed by -Wvla-parameter.)
   { dg-do compile }
   { dg-options "-Wall -Warray-parameter=2" } */

// Verify that equivalent forms don't tigger a warning.

typedef int IA1[1];
typedef int IA1x_[][1];
typedef int IA1x0[0][1];

void fia_x1 (int[][1]);
void fia_x1 (IA1[0]);
void fia_x1 (IA1x_);
void fia_x1 (IA1x0);
void fia_x1 (int[0][1]);
void fia_x1 (int[static 0][1]);

// Same as above one more time.
void fia_x1 (int[][1]);
void fia_x1 (IA1[0]);
void fia_x1 (IA1x_);
void fia_x1 (IA1x0);
void fia_x1 (int[0][1]);
void fia_x1 (int[static 0][1]);


void fia1x1 (int[1][1]);
void fia1x1 (int[1][1]);
void fia1x1 (int[static 1][1]);

void fia2x1 (int[2][1]);
void fia2x1 (int[2][1]);
void fia2x1 (int[static 2][1]);

void fia1x2 (int[1][2]);
void fia1x2 (int[1][2]);
void fia1x2 (int[static 1][2]);

void fia1x1_2x1 (int[1][1]);          // { dg-message "previously declared as 'int\\\[1]\\\[1]'" }
void fia1x1_2x1 (int[2][1]);          // { dg-warning "\\\[-Warray-parameter" }
void fia1x1_2x1 (int[static 1][1]);
void fia1x1_2x1 (int[static 2][1]);   // { dg-warning "\\\[-Warray-parameter" }


void fia2x1_1x1 (int[2][1]);          // { dg-message "previously declared as 'int\\\[2]\\\[1]'" }
void fia2x1_1x1 (int[1][1]);          // { dg-warning "\\\[-Warray-parameter" }
void fia2x1_1x1 (int[2][1]);
void fia2x1_1x1 (int[static 1][1]);   // { dg-warning "\\\[-Warray-parameter" }
void fia2x1_1x1 (int[static 2][1]);


extern int n1, n2;

void fca_xn1 (char[][n1]);
void fca_xn1 (char[0][n1]);
void fca_xn1 (char[static 0][n1]);

void fca1xn1_2xn1 (char[1][n1]);
void fca1xn1_2xn1 (char[2][n1]);        // { dg-warning "\\\[-Warray-parameter" }
void fca1xn1_2xn1 (char[1][n1]);
void fca1xn1_2xn1 (char[static 1][n1]);
void fca1xn1_2xn1 (char[static 2][n1]); // { dg-warning "\\\[-Warray-parameter" }


/* Exercise VLAs with a mismatch in the bound for an ordinary array.  */
void fvlax_y (int n, int[][n]);
void fvlax_y (int n, int[0][n]);
void fvlax_y (int n, int[1][n]);        // { dg-warning "argument 2 of type 'int\\\[1]\\\[n]' with mismatched bound" }
void fvlax_y (int n, int[2][n]);        // { dg-warning "argument 2 of type 'int\\\[2]\\\[n]' with mismatched bound" }
void fvlax_y (int n, int[3][n]);        // { dg-warning "argument 2 of type 'int\\\[3]\\\[n]' with mismatched bound" }

void fvlaxn_y (int n, int[][n]);
void fvlaxn_y (int n, int[0][n]);
void fvlaxn_y (int n, int[1][n]);       // { dg-warning "\\\[-Warray-parameter" }
void fvlaxn_y (int n, int[2][n]);       // { dg-warning "\\\[-Warray-parameter" }
void fvlaxn_y (int n, int[3][n]);       // { dg-warning "\\\[-Warray-parameter" }

void fvlaxx_y (int[][*]);
void fvlaxx_y (int[0][*]);
void fvlaxx_y (int[1][*]);              // { dg-warning "\\\[-Warray-parameter" }
void fvlaxx_y (int[2][*]);              // { dg-warning "\\\[-Warray-parameter" }
void fvlaxx_y (int[3][*]);              // { dg-warning "\\\[-Warray-parameter" }


// Verify an array of pointers to an array of function pointers.

void ffpa7_5 (void (* (* (* [7])[5])(void))(void));
// { dg-message "previously declared as 'void \\\(\\\* ?\\\(\\\* ?\\\(\\\*\\\[7]\\\)\\\[5]\\\)\\\(void\\\)\\\)\\\(void\\\)'" "note" { target *-*-* } .-1 }
void ffpa7_5 (void (* (* (* [6])[5])(void))(void));
// { dg-warning "argument 1 of type 'void \\\(\\\* ?\\\(\\\* ?\\\(\\\*\\\[6]\\\)\\\[5]\\\)\\\(void\\\)\\\)\\\(void\\\)' with mismatched bound" "" { target *-*-* } .-1 }
void ffpa7_5 (void (* (* (* [])[5])(void))(void));
// { dg-warning "argument 1 of type 'void \\\(\\\* ?\\\(\\\* ?\\\(\\\*\\\[]\\\)\\\[5]\\\)\\\(void\\\)\\\)\\\(void\\\)' with mismatched bound" "" { target *-*-* } .-1 }
void ffpa7_5 (void (* (* (* (*))[5])(void))(void));
// { dg-warning "argument 1 of type 'void \\\(\\\* ?\\\(\\\* ?\\\(\\\*\\\*\\\)\\\[5]\\\)\\\(void\\\)\\\)\\\(void\\\)' declared as a pointer" "" { target *-*-* } .-1 }

// Same as above but with array of pointers to a VLA of function pointers.
void ffpa7_n1 (void (* (* (* [7])[n1])(void))(void));
// { dg-message "previously declared as 'void \\\(\\\* ?\\\(\\\* ?\\\(\\\*\\\[7]\\\)\\\[n1]\\\)\\\(void\\\)\\\)\\\(void\\\)'" "note" { target *-*-* } .-1 }
void ffpa7_n1 (void (* (* (* [8])[n1])(void))(void));
// { dg-warning "argument 1 of type 'void \\\(\\\* ?\\\(\\\* ?\\\(\\\*\\\[8]\\\)\\\[n1]\\\)\\\(void\\\)\\\)\\\(void\\\)' with mismatched bound" "" { target *-*-* } .-1 }

void ffpa9_x (void (* (* (* [9])[*])(void))(void));
// { dg-message "previously declared as 'void \\\(\\\* ?\\\(\\\* ?\\\(\\\*\\\[9]\\\)\\\[\\\*]\\\)\\\(void\\\)\\\)\\\(void\\\)'" "pr?????" { xfail *-*-* } .-1 }
// { dg-message "previously declared as 'void \\\(\\\* ?\\\(\\\* ?\\\(\\\*\\\[9]\\\)\\\[0]\\\)\\\(void\\\)\\\)\\\(void\\\)'" "" { target *-*-* } .-2 }
void ffpa9_x (void (* (* (* [8])[*])(void))(void));
// { dg-warning "argument 1 of type 'void \\\(\\\* ?\\\(\\\* ?\\\(\\\*\\\[8]\\\)\\\[\\\*]\\\)\\\(void\\\)\\\)\\\(void\\\)' with mismatched bound" "pr?????" { xfail *-*-* } .-1 }
// { dg-warning "argument 1 of type 'void \\\(\\\* ?\\\(\\\* ?\\\(\\\*\\\[8]\\\)\\\[0]\\\)\\\(void\\\)\\\)\\\(void\\\)' with mismatched bound"  "" { target *-*-* } .-2 }

/* Verify a three-dimensional array of pointers to two-dimensional arrays
   of pointers to function pointers.  */

void ffpa7_5_3 (void (* (* (* (* [7])[5])[3])(void))(void));
// { dg-message "previously declared as 'void ?\\\(\\\* ?\\\(\\\* ?\\\(\\\* ?\\\(\\\* ?\\\[7]\\\)\\\[5]\\\)\\\[3]\\\)\\\(void\\\)\\\)\\\(void\\\)'" "note" { target *-*-* } .-1 }
void ffpa7_5_3 (void (* (* (* (* [1])[5])[3])(void))(void));
// { dg-warning "argument 1 of type 'void ?\\\(\\\* ?\\\(\\\* ?\\\(\\\* ?\\\(\\\* ?\\\[1]\\\)\\\[5]\\\)\\\[3]\\\)\\\(void\\\)\\\)\\\(void\\\)' with mismatched bound" "" { target *-*-* } .-1 }