https://gcc.gnu.org/bugzilla/show_bug.cgi?id=10837

--- Comment #25 from Josh Haberman <jhaberman at gmail dot com> ---
(In reply to Lukas Grätz from comment #24)
> (In reply to Josh Haberman from comment #23)
> > (In reply to Lukas Grätz from comment #22)
> > > I think the status should be changed into RESOLVED FIXED now. After PR
> > > 119483 and PR 121159 with GCC 16+ and 15.2+, tail call optimization is
> > > finally possible for noreturn functions. Just use the musttail attribute
> > > introduced by PR 83324.
> > 
> > That works as long as the function signature of the noreturn function
> > precisely matches the function signature of the caller.  In many cases,
> > you would need to add a wrapper around the noreturn function to make
> > them match.
> 
> Sorry, but if I understand you correctly, this has nothing to do with
> noreturn; it is a limitation of tail call optimization in general.
> 
> So this does not affect the present issue. If I am wrong, please provide an
> example to explain.

I was mistaken; I thought that GCC implemented the same rules as Clang for
musttail.  In Clang, musttail is rejected unless the parameters for the caller
and callee match, even if a tail call would technically be possible.

But after experimenting on Godbolt, I see that GCC does not have these
requirements.  Note how this example compiles on GCC but is rejected for
Clang: https://godbolt.org/z/Yc589hMM3

As a result, I now agree with you that `musttail` addresses the complaint in
this bug.  While it is odd and unexpected that `noreturn` will inhibit tail
calls, I agree that `musttail` appears to override this behavior, providing
an escape hatch for users who want tail calls on `noreturn` functions.

It is somewhat unfortunate that this requires the attribute to be at every
call site,  instead of on the `noreturn` function itself, but at least it is 
possible.

Reply via email to