Consider: ``` $ gcc --version gcc (GCC) 15.2.0 Copyright (C) 2025 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. $ cat /tmp/test1.c extern int f(void); static int g(void) { [[gnu::musttail]] return f(); return 42; } $ gcc -o /tmp/test1.o -c /tmp/test1.c /tmp/test1.c: In function ‘g’: /tmp/test1.c:5:10: error: cannot tail-call: return value must be a call 5 | return 42; | ^~ ``` However, this works: ``` static int g(void) { if (1) [[gnu::musttail]] return f(); return 42; } ```
Hmm,
Confirmed, this is a C front-end issue. once we see `[[gnu::musttail]]`, astate.musttail_p is never reset. I will fix this.
.
The workaround is to put each statement into an own compound statement to reset the state.
Created attachment 64461 [details] fix
The trunk branch has been updated by Andi Kleen <ak@gcc.gnu.org>: https://gcc.gnu.org/g:591a8ac50d8faf914391e616faf6311f2143fde7 commit r17-534-g591a8ac50d8faf914391e616faf6311f2143fde7 Author: Andi Kleen <ak@gcc.gnu.org> Date: Thu May 14 14:37:01 2026 -0700 pr124532: Reset musttail attribute in compound statements A compound statement didn't reset the musttail state after the statement with the attribute, which led to bogus errors later. Always reset it. PR c/124532 gcc/c/ChangeLog: * c-parser.cc (struct attr_state): Add reset method. (c_parser_compound_statement_nostart): Rename a to astate. Reset state before iterating statements. gcc/testsuite/ChangeLog: * c-c++-common/pr124532.c: New test.
The releases/gcc-16 branch has been updated by Andi Kleen <ak@gcc.gnu.org>: https://gcc.gnu.org/g:f1306d5ead2354ed2b7d142ee13f65a980fde424 commit r16-8920-gf1306d5ead2354ed2b7d142ee13f65a980fde424 Author: Andi Kleen <ak@gcc.gnu.org> Date: Thu May 14 14:37:01 2026 -0700 pr124532: Reset musttail attribute in compound statements A compound statement didn't reset the musttail state after the statement with the attribute, which led to bogus errors later. Always reset it. PR c/124532 gcc/c/ChangeLog: * c-parser.cc (struct attr_state): Add reset method. (c_parser_compound_statement_nostart): Rename a to astate. Reset state before iterating statements. gcc/testsuite/ChangeLog: * c-c++-common/pr124532.c: New test.
The releases/gcc-15 branch has been updated by Andi Kleen <ak@gcc.gnu.org>: https://gcc.gnu.org/g:4a7fcf5b32a979f9a009f5dc71140eceb7db1b1a commit r15-11172-g4a7fcf5b32a979f9a009f5dc71140eceb7db1b1a Author: Andi Kleen <ak@gcc.gnu.org> Date: Thu May 14 14:37:01 2026 -0700 pr124532: Reset musttail attribute in compound statements A compound statement didn't reset the musttail state after the statement with the attribute, which led to bogus errors later. Always reset it. PR c/124532 gcc/c/ChangeLog: * c-parser.cc (struct attr_state): Add reset method. (c_parser_compound_statement_nostart): Rename a to astate. Reset state before iterating statements. gcc/testsuite/ChangeLog: * c-c++-common/pr124532.c: New test.
patches checked in starting with gcc 15