Debian Codegraph @

gcc/testsuite/c-c++-common/torture/strub-callable2.c

raw
1 /* { dg-do compile } */
2 /* { dg-options "-fstrub=strict" } */
3 /* { dg-require-effective-target strub } */
4
5 /* Check that impermissible (cross-strub-context) calls are reported. */
6
7 extern int __attribute__ ((__strub__ ("callable"))) xcallable (void);
8 extern int __attribute__ ((__strub__ ("internal"))) xinternal (void);
9 extern int __attribute__ ((__strub__ ("at-calls"))) xat_calls (void);
10 extern int __attribute__ ((__strub__ ("disabled"))) xdisabled (void);
11
12 int __attribute__ ((__strub__ ("callable"))) callable (void);
13 int __attribute__ ((__strub__ ("internal"))) internal (void);
14 int __attribute__ ((__strub__ ("at-calls"))) at_calls (void);
15 int __attribute__ ((__strub__ ("disabled"))) disabled (void);
16
17 int __attribute__ ((__strub__)) var;
18 int var_user (void);
19
20 static inline int __attribute__ ((__always_inline__, __strub__ ("callable")))
21 icallable (void);
22 static inline int __attribute__ ((__always_inline__, __strub__ ("internal")))
23 iinternal (void);
24 static inline int __attribute__ ((__always_inline__, __strub__ ("at-calls")))
25 iat_calls (void);
26 static inline int __attribute__ ((__always_inline__, __strub__ ("disabled")))
27 idisabled (void);
28 static inline int __attribute__ ((__always_inline__))
29 ivar_user (void);
30
31 static inline int __attribute__ ((__always_inline__, __strub__ ("callable")))
32 i_callable (void) { return 0; }
33 static inline int __attribute__ ((__always_inline__, __strub__ ("internal")))
34 i_internal (void) { return var; }
35 static inline int __attribute__ ((__always_inline__, __strub__ ("at-calls")))
36 i_at_calls (void) { return var; }
37 static inline int __attribute__ ((__always_inline__, __strub__ ("disabled")))
38 i_disabled (void) { return 0; }
39 static inline int __attribute__ ((__always_inline__))
40 i_var_user (void) { return var; }
41
42 #define CALLS_GOOD_FOR_STRUB_CONTEXT(ISEP) \
43 do { \
44 ret += i ## ISEP ## at_calls (); \
45 ret += i ## ISEP ## internal (); \
46 ret += i ## ISEP ## var_user (); \
47 } while (0)
48
49 #define CALLS_GOOD_FOR_NONSTRUB_CONTEXT(ISEP) \
50 do { \
51 ret += internal (); \
52 ret += disabled (); \
53 ret += var_user (); \
54 \
55 ret += i ## ISEP ## disabled (); \
56 \
57 ret += xinternal (); \
58 ret += xdisabled (); \
59 } while (0)
60
61 #define CALLS_GOOD_FOR_EITHER_CONTEXT(ISEP) \
62 do { \
63 ret += i ## ISEP ## callable (); \
64 \
65 ret += callable (); \
66 ret += at_calls (); \
67 \
68 ret += xat_calls (); \
69 ret += xcallable (); \
70 } while (0)
71
72 /* Not a strub context, so it can call anything.
73 Explicitly declared as callable even from within strub contexts. */
74 int __attribute__ ((__strub__ ("callable")))
75 callable (void) {
76 int ret = 0;
77
78 /* CALLS_GOOD_FOR_STRUB_CONTEXT(); */
79 #if !OMIT_IMPERMISSIBLE_CALLS
80 ret += iat_calls (); /* { dg-error "in non-.strub. context" } */
81 ret += iinternal (); /* { dg-error "in non-.strub. context" } */
82 ret += ivar_user (); /* { dg-error "in non-.strub. context" } */
83 #endif
84 CALLS_GOOD_FOR_EITHER_CONTEXT();
85 CALLS_GOOD_FOR_NONSTRUB_CONTEXT();
86
87 return ret;
88 }
89
90 /* Internal strubbing means the body is a strub context, so it can only call
91 strub functions, and it's not itself callable from strub functions. */
92 int __attribute__ ((__strub__ ("internal")))
93 internal (void) {
94 int ret = var;
95
96 CALLS_GOOD_FOR_STRUB_CONTEXT();
97 CALLS_GOOD_FOR_EITHER_CONTEXT();
98 /* CALLS_GOOD_FOR_NONSTRUB_CONTEXT(); */
99 #if !OMIT_IMPERMISSIBLE_CALLS
100 ret += internal (); /* { dg-error "in .strub. context" } */
101 ret += disabled (); /* { dg-error "in .strub. context" } */
102 ret += var_user (); /* { dg-error "in .strub. context" } */
103
104 ret += idisabled (); /* { dg-error "in .strub. context" } */
105
106 ret += xinternal (); /* { dg-error "in .strub. context" } */
107 ret += xdisabled (); /* { dg-error "in .strub. context" } */
108 #endif
109
110 return ret;
111 }
112
113 int __attribute__ ((__strub__ ("at-calls")))
114 at_calls (void) {
115 int ret = var;
116
117 CALLS_GOOD_FOR_STRUB_CONTEXT();
118 CALLS_GOOD_FOR_EITHER_CONTEXT();
119 /* CALLS_GOOD_FOR_NONSTRUB_CONTEXT(); */
120 #if !OMIT_IMPERMISSIBLE_CALLS
121 ret += internal (); /* { dg-error "in .strub. context" } */
122 ret += disabled (); /* { dg-error "in .strub. context" } */
123 ret += var_user (); /* { dg-error "in .strub. context" } */
124
125 ret += idisabled (); /* { dg-error "in .strub. context" } */
126
127 ret += xinternal (); /* { dg-error "in .strub. context" } */
128 ret += xdisabled (); /* { dg-error "in .strub. context" } */
129 #endif
130
131 return ret;
132 }
133
134 int __attribute__ ((__strub__ ("disabled")))
135 disabled () {
136 int ret = 0;
137
138 /* CALLS_GOOD_FOR_STRUB_CONTEXT(); */
139 #if !OMIT_IMPERMISSIBLE_CALLS
140 ret += iat_calls (); /* { dg-error "in non-.strub. context" } */
141 ret += iinternal (); /* { dg-error "in non-.strub. context" } */
142 ret += ivar_user (); /* { dg-error "in non-.strub. context" } */
143 #endif
144 CALLS_GOOD_FOR_EITHER_CONTEXT();
145 CALLS_GOOD_FOR_NONSTRUB_CONTEXT();
146
147 return ret;
148 }
149
150 int
151 var_user (void) {
152 int ret = var;
153
154 CALLS_GOOD_FOR_STRUB_CONTEXT();
155 CALLS_GOOD_FOR_EITHER_CONTEXT();
156 /* CALLS_GOOD_FOR_NONSTRUB_CONTEXT(); */
157 #if !OMIT_IMPERMISSIBLE_CALLS
158 ret += internal (); /* { dg-error "in .strub. context" } */
159 ret += disabled (); /* { dg-error "in .strub. context" } */
160 ret += var_user (); /* { dg-error "in .strub. context" } */
161
162 ret += idisabled (); /* { dg-error "in .strub. context" } */
163
164 ret += xinternal (); /* { dg-error "in .strub. context" } */
165 ret += xdisabled (); /* { dg-error "in .strub. context" } */
166 #endif
167
168 return ret;
169 }
170
171 int
172 icallable (void)
173 {
174 int ret = 0;
175
176 /* CALLS_GOOD_FOR_STRUB_CONTEXT(_); */
177 #if !OMIT_IMPERMISSIBLE_CALLS
178 ret += i_at_calls (); /* { dg-error "in non-.strub. context" } */
179 ret += i_internal (); /* { dg-error "in non-.strub. context" } */
180 ret += i_var_user (); /* { dg-error "in non-.strub. context" } */
181 #endif
182 CALLS_GOOD_FOR_EITHER_CONTEXT(_);
183 CALLS_GOOD_FOR_NONSTRUB_CONTEXT(_);
184
185 return ret;
186 }
187
188 int
189 iinternal (void) {
190 int ret = var;
191
192 CALLS_GOOD_FOR_STRUB_CONTEXT(_);
193 CALLS_GOOD_FOR_EITHER_CONTEXT(_);
194 /* CALLS_GOOD_FOR_NONSTRUB_CONTEXT(_); */
195 #if !OMIT_IMPERMISSIBLE_CALLS
196 ret += internal (); /* { dg-error "in .strub. context" } */
197 ret += disabled (); /* { dg-error "in .strub. context" } */
198 ret += var_user (); /* { dg-error "in .strub. context" } */
199
200 ret += i_disabled (); /* { dg-error "in .strub. context" } */
201
202 ret += xinternal (); /* { dg-error "in .strub. context" } */
203 ret += xdisabled (); /* { dg-error "in .strub. context" } */
204 #endif
205
206 return ret;
207 }
208
209 int __attribute__ ((__always_inline__, __strub__ ("at-calls")))
210 iat_calls (void) {
211 int ret = var;
212
213 CALLS_GOOD_FOR_STRUB_CONTEXT(_);
214 CALLS_GOOD_FOR_EITHER_CONTEXT(_);
215 /* CALLS_GOOD_FOR_NONSTRUB_CONTEXT(_); */
216 #if !OMIT_IMPERMISSIBLE_CALLS
217 ret += internal (); /* { dg-error "in .strub. context" } */
218 ret += disabled (); /* { dg-error "in .strub. context" } */
219 ret += var_user (); /* { dg-error "in .strub. context" } */
220
221 ret += i_disabled (); /* { dg-error "in .strub. context" } */
222
223 ret += xinternal (); /* { dg-error "in .strub. context" } */
224 ret += xdisabled (); /* { dg-error "in .strub. context" } */
225 #endif
226
227 return ret;
228 }
229
230 int
231 idisabled () {
232 int ret = 0;
233
234 /* CALLS_GOOD_FOR_STRUB_CONTEXT(_); */
235 #if !OMIT_IMPERMISSIBLE_CALLS
236 ret += i_at_calls (); /* { dg-error "in non-.strub. context" } */
237 ret += i_internal (); /* { dg-error "in non-.strub. context" } */
238 ret += i_var_user (); /* { dg-error "in non-.strub. context" } */
239 #endif
240 CALLS_GOOD_FOR_EITHER_CONTEXT(_);
241 CALLS_GOOD_FOR_NONSTRUB_CONTEXT(_);
242
243 return ret;
244 }
245
246 int
247 ivar_user (void) {
248 int ret = var;
249
250 CALLS_GOOD_FOR_STRUB_CONTEXT(_);
251 CALLS_GOOD_FOR_EITHER_CONTEXT(_);
252 /* CALLS_GOOD_FOR_NONSTRUB_CONTEXT(_); */
253 #if !OMIT_IMPERMISSIBLE_CALLS
254 ret += internal (); /* { dg-error "in .strub. context" } */
255 ret += disabled (); /* { dg-error "in .strub. context" } */
256 ret += var_user (); /* { dg-error "in .strub. context" } */
257
258 ret += i_disabled (); /* { dg-error "in .strub. context" } */
259
260 ret += xinternal (); /* { dg-error "in .strub. context" } */
261 ret += xdisabled (); /* { dg-error "in .strub. context" } */
262 #endif
263
264 return ret;
265 }