| 1 |
/* PR middle-end/83859 - attribute to establish relation between parameters |
| 2 |
for buffer and its size |
| 3 |
{ dg-do compile } |
| 4 |
{ dg-options "-fpermissive -Wall -ftrack-macro-expansion=0" } */ |
| 5 |
|
| 6 |
int __attribute__ ((access)) |
| 7 |
access_v (void); /* { dg-error "wrong number of arguments specified for 'access' attribute" } */ |
| 8 |
|
| 9 |
int __attribute__ ((access ())) |
| 10 |
access___v (void); /* { dg-error "wrong number of arguments specified for 'access' attribute" } */ |
| 11 |
|
| 12 |
int __attribute__ ((access (rdwr))) |
| 13 |
rdwr_spelling (void); /* { dg-error "attribute .access. invalid mode 'rdwr'; expected one of 'read_only', 'read_write', 'write_only', or 'none'" } */ |
| 14 |
|
| 15 |
int __attribute__ ((access (read_write))) |
| 16 |
rdwr_v_all (void); /* { dg-error "attribute .access\\(read_write\\). missing an argument" } */ |
| 17 |
|
| 18 |
int __attribute__ ((access (read_write ()))) |
| 19 |
rdwr___v_all (void); /* { dg-error "attribute 'access' unexpected '\\(' after mode 'read_write'; expected a positional argument or '\\)'" } */ |
| 20 |
/* { dg-warning "implicit declaration of function 'read_write'" "" { target *-*-* } .-2 } */ |
| 21 |
|
| 22 |
|
| 23 |
int rdwr (void); |
| 24 |
|
| 25 |
int __attribute__ ((access (rdwr ()))) |
| 26 |
rdwr___v_all (void); /* { dg-error "attribute 'access' invalid mode 'rdwr'" } */ |
| 27 |
|
| 28 |
|
| 29 |
#define RDWR(...) __attribute__ ((access (read_write, __VA_ARGS__))) |
| 30 |
|
| 31 |
int RDWR (1) |
| 32 |
rdwr_pcv_1 (void*); |
| 33 |
|
| 34 |
int RDWR (2) |
| 35 |
rdwr_i_pcv_2 (int, void*); |
| 36 |
int RDWR (3) |
| 37 |
rdwr_i_i_pcv_3 (int, int, void*); |
| 38 |
|
| 39 |
int RDWR (0 + 1) |
| 40 |
rdwr_pcv_0p1 (void*); |
| 41 |
|
| 42 |
int RDWR (2 - 1) |
| 43 |
rdwr_pcv_2m1 (void*); |
| 44 |
|
| 45 |
int RDWR (1) |
| 46 |
rdwr_pcv_pi_1_1 (const void*, int*); /* { dg-error "attribute 'access\\(read_write, 1\\)' positional argument 1 references 'const'-qualified argument type 'const void \\*'" } */ |
| 47 |
|
| 48 |
int RDWR (1, 1) |
| 49 |
rdwr_pv_pi_1_1 (void*, int*); /* { dg-error "attribute 'access\\(read_write, 1, 1\\)' positional argument 2 references non-integer argument type 'void \\*'" } */ |
| 50 |
|
| 51 |
int RDWR (1, 2) |
| 52 |
rdwr_pcv_pc_1_2 (void*, char*); /* { dg-error "attribute .access\\(read_write, 1, 2\\)' positional argument 2 references non-integer argument type 'char \\*'" } */ |
| 53 |
|
| 54 |
int RDWR (2, 1) |
| 55 |
rdwr_pcd_pcv_2_1 (double*, void*); /* { dg-error "attribute .access\\(read_write, 2, 1\\)' positional argument 2 references non-integer argument type 'double \\*'" } */ |
| 56 |
|
| 57 |
int RDWR (2, 2) |
| 58 |
rdwr_pi_pcv_2_2 (int*, void*); /* { dg-error "positional argument 2 references non-integer argument type 'void \\*'" } */ |
| 59 |
|
| 60 |
int RDWR (4) |
| 61 |
rdwr_i_i_i_4 (int, int, int); /* { dg-error "attribute 'access\\(read_write, 4\\)' positional argument 1 value 4 exceeds number of function arguments 3" } */ |
| 62 |
|
| 63 |
int RDWR (1) |
| 64 |
rdwr_i_1 (int); /* { dg-error "attribute 'access\\(read_write, 1\\)' positional argument 1 references non-pointer argument type 'int'" } */ |
| 65 |
|
| 66 |
int RDWR (2) |
| 67 |
rdwr_i_pc (int, const char*); /* { dg-error "attribute 'access\\(read_write, 2\\)' positional argument 1 references 'const'-qualified argument type 'const char \\*'" } */ |
| 68 |
|
| 69 |
int RDWR (-1) |
| 70 |
rdwr_pcv_m1 (void*); /* { dg-error "attribute 'access\\(read_write, -1\\)' positional argument 1 invalid value -1" } */ |
| 71 |
|
| 72 |
int RDWR (1, -12345) |
| 73 |
rdwr_pcv_i_1_m12345 (void*, int*); /* { dg-error "attribute 'access\\(read_write, 1, -12345\\)' positional argument 2 invalid value -12345" } */ |
| 74 |
|
| 75 |
int RDWR ("blah") |
| 76 |
rdwr_pcv_str (void*); /* { dg-error "attribute 'access\\(read_write, \"blah\"\\)' invalid positional argument 1" } */ |
| 77 |
|
| 78 |
int RDWR (1, "foobar") |
| 79 |
rdwr_pcv_i_1_str (void*, int); /* { dg-error "attribute 'access\\(read_write, 1, \"foobar\"\\)' invalid positional argument 2" } */ |
| 80 |
|
| 81 |
/* Verify that attributes whose operands reference function pointers |
| 82 |
are rejected. */ |
| 83 |
typedef int F (int, int); |
| 84 |
RDWR (1) void rdwr_pf_1 (F*); /* { dg-error "attribute 'access\\(read_write, 1\\)' positional argument 1 references argument of function type 'F' \\{aka 'int\\(int, *int\\)'\\}" } */ |
| 85 |
|
| 86 |
/* Verify pointers to functions. */ |
| 87 |
void RDWR(2) (*prdwr_pv2)(int, void*); |
| 88 |
void RDWR(3, 1) (*prdwr_pv2_1)(int, void*, void*); |
| 89 |
|
| 90 |
/* Verify types. */ |
| 91 |
typedef RDWR (2) void rdwr_p2_t (int*, char*, void*); |
| 92 |
typedef RDWR (2) void rdwr_p2_1 (int, int*); |