On Tue, 25 Mar 2025, Andi Kleen wrote:
> On Tue, Mar 25, 2025 at 07:43:28PM +0300, Alexander Monakov wrote: > > Hello, > > > > FWIW I think Clang made a mistake in bending semantics in a way that is > > clearly > > misaligned with the general design of C and C++, where a language-native, > > so to > > speak, solution was available: introduce a scope for the local variables to > > indicate that they cannot escape to the intended tailcall: > > > > void foo(int v) > > { > > { > > int a; > > capture(&a); > > } > > tailcall(v); // this cannot refer to 'a', even though it escaped earlier > > } > > This is not a universal fix? e.g. consider a case like > > void foo(int v) > { > int a; > capture(&a); > if (condition) > return tailcall(v); > // do something with a > } This can be rewritten as void foo(int v) { { int a; capture(&a); if (condition) goto tail_position; // do something with a } tail_position: tailcall(v); } or with 'do { ... if (...) break; ...} while (0)' when one prefers that to goto. Alexander