https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114824
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 zeroed. See this function: #include <stdio.h> __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.