From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 7393B3858D3C; Tue, 23 Apr 2024 10:24:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7393B3858D3C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1713867859; bh=sWUr27hIJ3RElU5KzpJbbqLEEMlHF0A5hZhe6A05PNk=; h=From:To:Subject:Date:From; b=F/GneDd8a2vvJ/Wux3qxkmOuxJFZaTRQpj9s2NGPCnKI51YsOm/bNL5Dbz7LZBdCb +zF1yFmVh/+LPFfO5lLFkwK2Czjd4FV8Wti/fWluMtc9rTygK5bbW0DukpJQ8f8HqW KOsMjE9ZtJ4IL2gi8DtUfwBu6FrQc2poIrE5YK0g= From: "mikulas at artax dot karlin.mff.cuni.cz" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/114824] New: gcc doesn't respect __attribute__((zero_call_used_regs("used"))) when performing a tail call optimization Date: Tue, 23 Apr 2024 10:24:19 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 14.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: mikulas at artax dot karlin.mff.cuni.cz X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: 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=3D114824 Bug ID: 114824 Summary: gcc doesn't respect __attribute__((zero_call_used_regs("used"))) when performing a tail call optimization Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: mikulas at artax dot karlin.mff.cuni.cz Target Milestone: --- If a function has the attribute __attribute__((zero_call_used_regs("used"))) and the function ends with a sibling call, the used registers are not zeroe= d. See this function: #include __attribute__((zero_call_used_regs("used"))) void f(void) { __asm__ volatile("" ::: "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7"); printf("Hello World!\n"); } Compile it with "gcc -S -o - -O2 call.c -Wall -Wextra" - the result is: f: adrp x0, .LC0 add x0, x0, :lo12:.LC0 b puts If we disable the tail call optimization, the registers x0 - x7 are cleared properly: gcc -S -o - -O2 call.c -Wall -Wextra -fno-optimize-sibling-calls f: stp x29, x30, [sp, -16]! mov x29, sp adrp x0, .LC0 add x0, x0, :lo12:.LC0 bl puts ldp x29, x30, [sp], 16 mov x0, 0 mov x1, 0 mov x2, 0 mov x3, 0 mov x4, 0 mov x5, 0 mov x6, 0 mov x7, 0 mov x16, 0 mov x17, 0 ret I tested it on arm64 and x86-64 and both of them suffer from this problem.=