From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id AC76F3858CD1; Fri, 26 Apr 2024 17:48:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AC76F3858CD1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1714153714; bh=DQnO11RE21SIXvtMMvGKzS4yd6vY0cMPkBqn0IjNf84=; h=From:To:Subject:Date:In-Reply-To:References:From; b=pH40+JBWtqqGKS6qhmQjjvzyY+mL1Dq6u0R7WUtiAhpZLWtiYFR8ITdGHLKjUalXm X4M+Ordsm8x0N/VgmhYumGEyCbGFbvLxHni3TdZSlsNH/Qq/yTO6BiThAXY55nmI7R 5hbSyM5IGyEgeGpb82BcNG/QH2cv6GjDfQbga5xY= From: "wilco at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/114843] aarch64: epilogue in _Unwind_RaiseException corrupts return value due to __builtin_eh_return Date: Fri, 26 Apr 2024 17:48:34 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Version: 14.0 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: critical X-Bugzilla-Who: wilco at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: pinskia at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D114843 --- Comment #17 from Wilco --- (In reply to Andrew Pinski from comment #16) > Patch posted with all of the testcases included: > https://gcc.gnu.org/pipermail/gcc-patches/2024-April/650080.html Not nearly enough testcases... What about: void g(void); int f(long offset, void *handler) { g(); if (offset > 5) return arr[offset]; __builtin_eh_return (offset, handler); } With -O2 -fomit-frame-pointer: f: .LFB0: .cfi_startproc stp x30, x0, [sp, -64]! .cfi_def_cfa_offset 64 .cfi_offset 30, -64 .cfi_offset 0, -56 stp x1, x2, [sp, 16] stp x3, x19, [sp, 32] .cfi_offset 1, -48 .cfi_offset 2, -40 .cfi_offset 3, -32 .cfi_offset 19, -24 mov x19, x0 str x20, [sp, 48] .cfi_offset 20, -16 mov x20, x1 bl g cmp x19, 5 ble .L8 mov w0, w19 ldp x19, x20, [sp, 40] ldp x30, x0, [sp], 64 ****** oops .cfi_remember_state .cfi_restore 0 .cfi_restore 30 .cfi_restore 19 .cfi_restore 20 .cfi_def_cfa_offset 0 ret .L8: .cfi_restore_state mov x5, x19 ldp x1, x2, [sp, 16] mov x6, x20 ldp x3, x19, [sp, 32] ldr x20, [sp, 48] ldp x30, x0, [sp], 64 .cfi_restore 0 .cfi_restore 30 .cfi_restore 20 .cfi_restore 3 .cfi_restore 19 .cfi_restore 1 .cfi_restore 2 .cfi_def_cfa_offset 0 add sp, sp, x5 br x6 .cfi_endproc So I don't believe you should change aarch64_pop_regs at all - it's too lat= e to change things and just adds unnecessary complexity and more bugs. The best option would be to handle eh_return explicitly and insert the extra push/po= ps rather than treating them like a generic callee-save (because clearly they = are not anymore).=