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]> Diff: --- gcc/testsuite/g++.dg/torture/pr128147.C | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/gcc/testsuite/g++.dg/torture/pr128147.C b/gcc/testsuite/g++.dg/torture/pr128147.C index 20d13a64072a..29604b8bf879 100644 --- a/gcc/testsuite/g++.dg/torture/pr128147.C +++ b/gcc/testsuite/g++.dg/torture/pr128147.C @@ -11,9 +11,14 @@ on_segv (int) throw 1; } +// Load p from *pp first so that the trapping load *p is not the first +// instruction of f. Unwinders that look up a signal frame with PC - 2 +// (ARM EHABI) would otherwise find the preceding function. + __attribute__((noipa)) int -f (int *p, int c) +f (int **pp, int c) { + int *p = *pp; int x = *p; if (c) return x; @@ -29,7 +34,7 @@ main () return 0; try { - f (p, 0); + f (&p, 0); } catch (int) {
