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

--- Comment #2 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <ja...@gcc.gnu.org>:

https://gcc.gnu.org/g:e176456cfe5b1013bbfc24853265dfb13673011c

commit r15-9003-ge176456cfe5b1013bbfc24853265dfb13673011c
Author: Jakub Jelinek <ja...@redhat.com>
Date:   Fri Mar 28 10:49:40 2025 +0100

    tailc: Handle musttail noreturn calls [PR119483]

    The following (first) testcase is accepted by clang (if clang::musttail)
    and rejected by gcc, because we discover the call is noreturn and then bail
    out because we don't want noreturn tailcalls.
    The general reason not to support noreturn tail calls is for cases like
    abort where we want nicer backtrace, but if user asks explicitly to
    musttail a call which either is explicitly noreturn or is implicitly
    determined to be noreturn, I don't see a reason why we couldn't do that.
    Both for tail calls and tail recursions.

    An alternative would be to keep rejecting musttail to explicit noreturn,
    but not actually implicitly mark anything as noreturn if it has any
musttail
    calls.  But it is unclear how we could do that, such marking is I think
done
    typically before IPA and e.g. for LTO we won't know whether some other TU
    could have musttail calls to it.  And keeping around both explicit and
    implicit noreturn bits would be ugly.  Well, I guess we could differentiate
    between presence of noreturn/_Noreturn attributes and just ECF_NORETURN
    without those, but then tailc would still need to support it, just error
out
    if it was explicit.

    2025-03-28  Jakub Jelinek  <ja...@redhat.com>

            PR tree-optimization/119483
            * tree-tailcall.cc (find_tail_calls): Handle noreturn musttail
            calls.
            (eliminate_tail_call): Likewise.
            (tree_optimize_tail_calls_1): If cfun->has_musttail and
            diag_musttail, handle also basic blocks with no successors
            with noreturn musttail calls.
            * calls.cc (can_implement_as_sibling_call_p): Allow ECF_NORETURN
            calls if they are musttail calls.

            * c-c++-common/pr119483-1.c: New test.
            * c-c++-common/pr119483-2.c: New test.

Reply via email to