You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[clang] Lifetime of locals must end before musttail call (#109255)
The lifetimes of local variables and function parameters must end before
the call to a [[clang::musttail]] function, instead of before the
return, because we will not have a stack frame to hold them when doing
the call.
This documents this limitation, and adds diagnostics to warn about some
code which is invalid because of it.
// Test diagnostics for lifetimes of local variables, which end earlier for a
272
+
// musttail call than for a nowmal one.
273
+
274
+
voidTakesIntAndPtr(int, int *);
275
+
voidPassAddressOfLocal(int a, int *b) {
276
+
int c;
277
+
[[clang::musttail]] returnTakesIntAndPtr(0, &c); // expected-warning {{address of stack memory associated with local variable 'c' passed to musttail function}}
278
+
}
279
+
voidPassAddressOfParam(int a, int *b) {
280
+
[[clang::musttail]] returnTakesIntAndPtr(0, &a); // expected-warning {{address of stack memory associated with parameter 'a' passed to musttail function}}
281
+
}
282
+
voidPassValues(int a, int *b) {
283
+
[[clang::musttail]] returnTakesIntAndPtr(a, b);
284
+
}
285
+
286
+
voidTakesIntAndRef(int, constint &);
287
+
voidPassRefOfLocal(int a, constint &b) {
288
+
int c;
289
+
[[clang::musttail]] returnTakesIntAndRef(0, c); // expected-warning {{address of stack memory associated with local variable 'c' passed to musttail function}}
290
+
}
291
+
voidPassRefOfParam(int a, constint &b) {
292
+
[[clang::musttail]] returnTakesIntAndRef(0, a); // expected-warning {{address of stack memory associated with parameter 'a' passed to musttail function}}
293
+
}
294
+
intReturnInt();
295
+
voidPassRefOfTemporary(int a, constint &b) {
296
+
[[clang::musttail]] returnTakesIntAndRef(0, ReturnInt()); // expected-warning {{passing address of local temporary object to musttail function}}
0 commit comments