| 1 |
/* PR 50584 - No warning for passing small array to C99 static array declarator |
| 2 |
Exercise interaction between explicit attribute access and VLA parameters. |
| 3 |
{ dg-do compile } |
| 4 |
{ dg-options "-Wall" } */ |
| 5 |
|
| 6 |
#define RW(...) __attribute__ ((access (read_write, __VA_ARGS__))) |
| 7 |
|
| 8 |
|
| 9 |
void f1 (int n, int[n], int); // { dg-message "designating the bound of variable length array argument 2" "note" } |
| 10 |
|
| 11 |
// Verify that a redundant attribute access doesn't trigger a warning. |
| 12 |
RW (2, 1) void f1 (int n, int[n], int); |
| 13 |
|
| 14 |
RW (2, 3) void f1 (int n, int[n], int); // { dg-warning "attribute 'access\\\(read_write, 2, 3\\\)' positional argument 2 conflicts with previous designation by argument 1" } |
| 15 |
|
| 16 |
|
| 17 |
/* Verify that applying the attribute to a VLA with an unspecified bound |
| 18 |
doesn't trigger any warnings, both with and without a size operand. */ |
| 19 |
void f2 (int, int[*], int); |
| 20 |
RW (2) void f2 (int, int[*], int); |
| 21 |
RW (2, 3) void f2 (int, int[*], int); |
| 22 |
|
| 23 |
/* Designating a parameter that comes before the VLA is the same as |
| 24 |
using the standard VLA int[n] syntax. It might be worth issuing |
| 25 |
a portability warning suggesting to prefer the standard syntax. */ |
| 26 |
void f3 (int, int[*], int); |
| 27 |
RW (2, 1) void f3 (int, int[*], int); |
| 28 |
|
| 29 |
/* Designating a parameter that comes after the VLA cannot be expressed |
| 30 |
using the standard VLA int[n] syntax. Verify it doesn't trigger |
| 31 |
a warning. */ |
| 32 |
void f4 (int, int[*], int); |
| 33 |
RW (2, 3) void f4 (int, int[*], int); |
| 34 |
|
| 35 |
/* Also verify the same on the same declaration. */ |
| 36 |
void f5 (int[*], int) RW (1, 2); |
| 37 |
RW (1, 2) void f5 (int[*], int); |
| 38 |
RW (1, 2) void f5 (int[*], int) RW (1, 2); |
| 39 |
|
| 40 |
|
| 41 |
/* Verify that designating a VLA parameter with an explicit bound without |
| 42 |
also designating the same bound parameter triggers a warning (it has |
| 43 |
a different meaning). */ |
| 44 |
void f7 (int n, int[n]); // { dg-message "21:note: designating the bound of variable length array argument 2" "note" } |
| 45 |
RW (2) void f7 (int n, int[n]); // { dg-warning "attribute 'access\\\(read_write, 2\\\)' missing positional argument 2 provided in previous designation by argument 1" } |
| 46 |
|
| 47 |
void f8 (int n, int[n]); |
| 48 |
RW (2, 1) void f8 (int n, int[n]); |
| 49 |
|
| 50 |
|
| 51 |
void f9 (int, char[]); // { dg-message "25:note: previously declared as an ordinary array 'char\\\[]'" note" } |
| 52 |
RW (2) void f9 (int n, char a[n]) // { dg-warning "argument 2 of type 'char\\\[n]' declared as a variable length array" } |
| 53 |
// { dg-warning "attribute 'access *\\\(read_write, 2\\\)' positional argument 2 missing in previous designation" "" { target *-*-* } .-1 } |
| 54 |
// { dg-message "24:note: designating the bound of variable length array argument 2" "note" { target *-*-* } .-2 } |
| 55 |
{ (void)&n; (void)&a; } |
| 56 |
|
| 57 |
|
| 58 |
void f10 (int, char[]); // { dg-message "26:note: previously declared as an ordinary array 'char\\\[]'" "note" } |
| 59 |
RW (2, 1) void f10 (int n, char a[n]) // { dg-warning "attribute 'access *\\\(read_write, 2, 1\\\)' positional argument 2 missing in previous designation" "pr????" { xfail *-*-* } } |
| 60 |
// { dg-warning "argument 2 of type 'char\\\[n]' declared as a variable length array" "" { target *-*-* } .-1 } |
| 61 |
{ (void)&n; (void)&a; } |
| 62 |
|
| 63 |
/* Verify that redeclaring a function with attribute access applying |
| 64 |
to an array parameter of any form is not diagnosed. */ |
| 65 |
void f12__ (int, int[]) RW (2, 1); |
| 66 |
RW (2, 1) void f12__ (int, int[]); |
| 67 |
|
| 68 |
void f12_3 (int, int[3]) RW (2, 1); |
| 69 |
RW (2, 1) void f12_3 (int, int[3]); |
| 70 |
|
| 71 |
void f12_n (int n, int[n]) RW (2, 1); |
| 72 |
RW (2, 1) void f12_n (int n, int[n]); |
| 73 |
|
| 74 |
void f12_x (int, int[*]) RW (2, 1); |
| 75 |
RW (2, 1) void f12_x (int, int[*]); |
| 76 |
|
| 77 |
void f13__ (int, int[]); |
| 78 |
RW (2, 1) void f13__ (int, int[]); |
| 79 |
|
| 80 |
void f13_5 (int, int[5]); |
| 81 |
RW (2, 1) void f13_5 (int, int[5]); |
| 82 |
|
| 83 |
void f13_n (int n, int[n]); |
| 84 |
RW (2, 1) void f13_n (int n, int[n]); |
| 85 |
|
| 86 |
void f13_x (int, int[*]); |
| 87 |
RW (2, 1) void f13_x (int, int[*]); |
| 88 |
|
| 89 |
RW (2, 1) void f14__ (int, int[]); |
| 90 |
void f14__ (int, int[]); |
| 91 |
|
| 92 |
RW (2, 1) void f14_7 (int, int[7]); |
| 93 |
void f14_7 (int, int[7]); |
| 94 |
|
| 95 |
RW (2, 1) void f14_n (int n, int[n]); |
| 96 |
void f14_n (int n, int[n]); |
| 97 |
|
| 98 |
RW (2, 1) void f14_x (int, int[*]); |
| 99 |
void f14_x (int, int[*]); |
| 100 |
|
| 101 |
typedef void G1 (int n, int[n], int); |
| 102 |
|
| 103 |
G1 g1; |
| 104 |
|
| 105 |
/* The warning is about the attribute positional argument 2 which refers |
| 106 |
to the last function argument. Ideally, the caret would be under |
| 107 |
the corresponding function argument, i.e., the last one here) but |
| 108 |
that location isn't available yet. Verify that the caret doesn't |
| 109 |
point to function argument 1 which is the VLA bound (that's what |
| 110 |
the caret in the note points to). */ |
| 111 |
RW (2, 3) void g1 (int n, int[n], int); // { dg-warning "16: attribute 'access *\\\(read_write, 2, 3\\\)' positional argument 2 conflicts with previous designation by argument 3" } |
| 112 |
// { dg-message "24:designating the bound of variable length array argument 2" "note" { target *-*-* } .-1 } |