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

--- Comment #4 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Kyrylo Tkachov <[email protected]>:

https://gcc.gnu.org/g:55f987b0064c0c74f7faa13ed4f770969a9dd816

commit r17-6596-g55f987b0064c0c74f7faa13ed4f770969a9dd816
Author: Kyrylo Tkachov <[email protected]>
Date:   Mon Nov 23 00:48:27 2026 -0800

    testsuite: Make g++.dg/torture/pr128147.C pass on Arm [PR128147]

    Linaro CI reports "terminate called after throwing an instance of 'int'"
    for g++.dg/torture/pr128147.C at -O1 on armv8l-unknown-linux-gnueabihf
    (armv8-a, thumb).  The other optimization levels pass.

    With -fnon-call-exceptions at -O1 the trapping load is the first
    instruction of f:

      _Z1fPii:
            ldr     r0, [r0]
            cmp     r1, #0
            it      eq
            moveq   r0, r1
            bx      lr

    get_eit_entry in libgcc/unwind-arm-common.inc subtracts 2 from the
    return address before the unwind table lookup, with no exception for
    signal frames.  For a fault at the function entry the lookup address is
    before f, so it lands in the preceding function and the exception is not
    propagated to main.  At -O2 and above cmp comes first and at -O0 f has a
    prologue, so the fault is not at the entry.  The code generated for f is
    correct and the sink fix works as intended.

    Load the pointer from a pointer argument first, so that the trapping
    load is never the first instruction of f.

    The cross compiler assembly for the new f starts with a non-trapping load:

      ldr     r3, [r0]
      ldr     r0, [r3]

    This is expected to avoid the failure on Arm.

    gcc/testsuite/ChangeLog:

            PR tree-optimization/128147
            * g++.dg/torture/pr128147.C (f): Take a pointer to the pointer and
            load it first so that the trapping load is not the first
instruction.
            (main): Update call.

    Signed-off-by: Kyrylo Tkachov <[email protected]>

Reply via email to