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

--- Comment #12 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:b9523a935aaa28ffae9118e199a2f43a8a98e27e

commit r16-1625-gb9523a935aaa28ffae9118e199a2f43a8a98e27e
Author: Jakub Jelinek <ja...@redhat.com>
Date:   Mon Jun 23 15:58:55 2025 +0200

    expand: Allow musttail tail calls with -fsanitize=address [PR120608]

    The following testcase is rejected by GCC 15 but accepted (with
    s/gnu/clang/) by clang.
    The problem is that we want to execute a sequence of instructions to
    unpoison all automatic variables in the function and mark the var block
    allocated for use-after-return sanitization poisoned after the call,
    so we were just disabling tail calls if there are any instructions
    returned from asan_emit_stack_protection.
    It is fine and necessary for normal tail calls, but for musttail
    tail calls we actually document that accessing the automatic vars of
    the caller is UB as if they end their lifetime right before the tail
    call, so we also want address sanitizer user-after-return to diagnose
    that.

    The following patch will only disable normal tail calls when that sequence
    is present, for musttail it will arrange to emit a copy of that sequence
    before the tail call sequence.  That sequence only tweaks the shadow memory
    and nothing in the code emitted by call expansion should touch the shadow
    memory, so it is ok to emit it already before argument setup.

    2025-06-23  Jakub Jelinek  <ja...@redhat.com>

            PR middle-end/120608
            * cfgexpand.cc: Include rtl-iter.h.
            (expand_gimple_tailcall): Add ASAN_EPILOG_SEQ argument, if non-NULL
            and expand_gimple_stmt emitted a tail call, emit a copy of that
            insn sequence before the call sequence.
            (expand_gimple_basic_block): Remove DISABLE_TAIL_CALLS argument,
add
            ASAN_EPILOG_SEQ argument.  Disable tail call flag only on
non-musttail
            calls if that flag is set, pass it to expand_gimple_tailcall.
            (pass_expand::execute): Pass VAR_RET_SEQ directly as last
            expand_gimple_basic_block argument rather than its comparison with
            NULL.

            * g++.dg/asan/pr120608.C: New test.

Reply via email to