On Fri, Mar 21, 2025 at 08:31:35AM -0400, Jason Merrill wrote: > > Not sure I like this, but if others (e.g. Richi, Joseph, Jason) are ok with > > it I can live with it. But we'd need a good documentation, ideally some > > some new warning about it (perhaps enabled in -Wextra) and testcase > > coverage. > > Looking around, clang warns for > > int foo (int *); > > int bar (int *x) > > { > > *x = 42; > > int a = 0; > > [[clang::musttail]] return foo (&a); > > } > > by default (without -Wall/-Wextra) with > > warning: address of stack memory associated with local variable 'a' passed > > to musttail function [-Wreturn-stack-address] > > This could even be added to -Wreturn-local-addr. > > > Dunno if that warning is about other stuff or just that. > > If just that, perhaps we'd need multiple levels for it, diagnose passing > > those to musttail arguments by default and have in -Wextra stronger variant > > that would diagnose even the > > int baz (int *x) > > { > > *x = 42; > > int a = 0; > > foo (&a); > > [[clang::musttail]] return foo (nullptr); > > } > > case, i.e. escaped variables that are still in scope. > > That variant of the warning perhaps should suggest to users to end the > > lifetime of those variables before the musttail call. > > I agree that it would be good to warn about this case, perhaps even by > default, but that it should be possible to disable this warning without also > disabling the diagnostic about foo(&a).
Yes. And I really think we should have two levels of the warning, one for a must case when any of the musttail call arguments are addresses of local variables (regardless if still in scope or not), that is something that should be warned about by default unless disabled, and then a address may escape to musttail call case (at the places in the patch, enabled in -Wextra or maybe -Wall). Jakub