1 /* PR middle-end/83859 - attribute to establish relation between parameters
2 for buffer and its size
3 Test to verify the handling of attribute access (read_only) syntax.
4 { dg-do compile }
5 { dg-options "-Wall -ftrack-macro-expansion=0" } */
6
7 int __attribute__ ((access))
8 access_v (void); // { dg-error "wrong number of arguments specified for 'access' attribute" }
9
10 int __attribute__ ((access ()))
11 access___v (void); // { dg-error "wrong number of arguments specified for 'access' attribute" }
12
13 int __attribute__ ((access (rdonly)))
14 rdonly_spelling (void); // { dg-error "attribute .access. invalid mode 'rdonly'; expected one of 'read_only', 'read_write', 'write_only', or 'none'" }
15
16 int __attribute__ ((access (read_only)))
17 rdonly_v_all (void); // { dg-error "attribute .access\\(read_only\\). missing an argument" }
18
19 int __attribute__ ((access (read_only ())))
20 rdonly___v_all (void); // { dg-error "attribute 'access' unexpected '\\(' after mode 'read_only'; expected a positional argument or '\\)'" }
21 // { dg-warning "implicit declaration of function 'read_only'" "" { target *-*-* } .-2 }
22
23
24 int rdonly (void);
25
26 int __attribute__ ((access (rdonly ())))
27 rdonly___v_all (void); // { dg-error "attribute 'access' invalid mode 'rdonly'" }
28
29
30 int __attribute__ ((access (read_only)))
31 rdonly_i_all (int); // { dg-error "attribute .access\\(read_only\\). missing an argument" }
32
33 #define rdonly __attribute__ ((access (read_only)))
34 #define RDONLY(...) __attribute__ ((access (read_only, __VA_ARGS__)))
35
36 int RDONLY (1)
37 rdonly_pcv_1 (const void*);
38 int RDONLY (2)
39 rdonly_i_pcv_2 (int, const void*);
40 int RDONLY (3)
41 rdonly_i_i_pcv_3 (int, int, const void*);
42
43 int RDONLY (0 + 1)
44 rdonly_pcv_0p1 (const void*);
45
46 int RDONLY (2 - 1)
47 rdonly_pcv_2m1 (const void*);
48
49 int RDONLY (1, 1)
50 rdonly_pv_pi_1_1 (const void*, const int*); // { dg-error "attribute 'access\\(read_only, 1, 1\\)' positional argument 2 references non-integer argument type 'const void \\*'" }
51
52 int RDONLY (1, 2)
53 rdonly_pcv_pc_1_2 (const void*, char*); // { dg-error "attribute .access\\(read_only, 1, 2\\)' positional argument 2 references non-integer argument type 'char \\*'" }
54
55 int RDONLY (2, 1)
56 rdonly_pcd_pcv_2_1 (const double*, const void*); // { dg-error "attribute .access\\(read_only, 2, 1\\)' positional argument 2 references non-integer argument type 'const double \\*'" }
57
58 int RDONLY (2, 2)
59 rdonly_pi_pcv_2_2 (int*, const void*); // { dg-error "positional argument 2 references non-integer argument type 'const void \\*'" }
60
61 int RDONLY (4)
62 rdonly_i_i_i_4 (int, int, int); // { dg-error "attribute 'access\\(read_only, 4\\)' positional argument 1 value 4 exceeds number of function arguments 3" }
63
64 int RDONLY (1)
65 rdonly_i_1 (int); // { dg-error "attribute 'access\\(read_only, 1\\)' positional argument 1 references non-pointer argument type 'int'" }
66
67 // It's okay if the pointer argument is non-const, although a separate
68 // warning encouraging one might be worthwhile. Maybe something like
69 // -Wsuggest-const.
70 int RDONLY (2)
71 rdonly_i_pc (int, char*);
72
73 int RDONLY (-1)
74 rdonly_pcv_m1 (const void*); // { dg-error "attribute 'access\\(read_only, -1\\)' positional argument 1 invalid value -1" }
75
76 int RDONLY (1, -12345)
77 rdonly_pcv_i_1_m12345 (const void*, int*); // { dg-error "attribute 'access\\(read_only, 1, -12345\\)' positional argument 2 invalid value -12345" }
78
79 int RDONLY ("blah")
80 rdonly_pcv_str (const void*); // { dg-error "attribute 'access\\(read_only, \"blah\"\\)' invalid positional argument 1" }
81
82 int RDONLY (1, "foobar")
83 rdonly_pcv_i_1_str (const void*, int); // { dg-error "attribute 'access\\(read_only, 1, \"foobar\"\\)' invalid positional argument 2" }
84
85 // Verify that attributes whose operands reference function pointers
86 // are rejected.
87 typedef int F (int, int);
88 RDONLY (1) void rdwr_pf_1 (F*); // { dg-error "attribute 'access\\(read_only, 1\\)' positional argument 1 references argument of function type 'F' \\{aka 'int\\(int, *int\\)'\\}" }
89
90 // Verify pointers to functions.
91 void RDONLY(2) (*prdonly_pcv2)(int, const void*);
92 void RDONLY(3, 1) (*prdonly_pcv2_1)(int, void*, const void*);
93
94 // Verify types.
95 typedef RDONLY (2) void rdonly_p2_t (const int*, const char*, const void*);
96 typedef RDONLY (2) void rdonly_p2_1 (int, const int*);