[clang] [clang] Lifetime of locals must end before musttail call (PR #109255)
Haojian Wu via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 20 01:33:13 PDT 2024
================
@@ -267,3 +267,30 @@ namespace ns {}
void TestCallNonValue() {
[[clang::musttail]] return ns; // expected-error {{unexpected namespace name 'ns': expected expression}}
}
+
+// Test diagnostics for lifetimes of local variables, which end earlier for a
+// musttail call than for a nowmal one.
+
+void TakesIntAndPtr(int, int *);
+void PassAddressOfLocal(int a, int *b) {
+ int c;
+ [[clang::musttail]] return TakesIntAndPtr(0, &c); // expected-warning {{address of stack memory associated with local variable 'c' passed to musttail function}}
----------------
hokein wrote:
can you add a test where a function call is used in the argument? something like
```
int foo();
void test(int a, const int &b) {
int c;
[[clang::musttail]] return test(0, foo());
}
```
https://github.com/llvm/llvm-project/pull/109255
More information about the cfe-commits
mailing list