* [Bug c/83324] [feature request] Pragma or special syntax for guaranteed tail calls
[not found] <bug-83324-4@http.gcc.gnu.org/bugzilla/>
@ 2021-12-04 16:14 ` pietro.gcc at sociotechnical dot xyz
2023-11-16 4:41 ` pinskia at gcc dot gnu.org
` (32 subsequent siblings)
33 siblings, 0 replies; 34+ messages in thread
From: pietro.gcc at sociotechnical dot xyz @ 2021-12-04 16:14 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83324
pietro <pietro.gcc at sociotechnical dot xyz> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |pietro.gcc at sociotechnical dot x
| |yz
--- Comment #2 from pietro <pietro.gcc at sociotechnical dot xyz> ---
I created a plugin that lets you annotate a whole function as musttail:
https://github.com/pietro/gcc-musttail-plugin/
I think that in order to add an attribute to the return statement like clang
has done the parser for the C frontend needs to be modified.
^ permalink raw reply [flat|nested] 34+ messages in thread
* [Bug c/83324] [feature request] Pragma or special syntax for guaranteed tail calls
[not found] <bug-83324-4@http.gcc.gnu.org/bugzilla/>
2021-12-04 16:14 ` [Bug c/83324] [feature request] Pragma or special syntax for guaranteed tail calls pietro.gcc at sociotechnical dot xyz
@ 2023-11-16 4:41 ` pinskia at gcc dot gnu.org
2023-11-16 4:49 ` dje at gcc dot gnu.org
` (31 subsequent siblings)
33 siblings, 0 replies; 34+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-11-16 4:41 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83324
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |dje at gcc dot gnu.org
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 112558 has been marked as a duplicate of this bug. ***
^ permalink raw reply [flat|nested] 34+ messages in thread
* [Bug c/83324] [feature request] Pragma or special syntax for guaranteed tail calls
[not found] <bug-83324-4@http.gcc.gnu.org/bugzilla/>
2021-12-04 16:14 ` [Bug c/83324] [feature request] Pragma or special syntax for guaranteed tail calls pietro.gcc at sociotechnical dot xyz
2023-11-16 4:41 ` pinskia at gcc dot gnu.org
@ 2023-11-16 4:49 ` dje at gcc dot gnu.org
2023-11-16 17:27 ` mikpelinux at gmail dot com
` (30 subsequent siblings)
33 siblings, 0 replies; 34+ messages in thread
From: dje at gcc dot gnu.org @ 2023-11-16 4:49 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83324
David Edelsohn <dje at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Priority|P3 |P2
Ever confirmed|0 |1
Last reconfirmed| |2023-11-16
Status|UNCONFIRMED |NEW
--- Comment #4 from David Edelsohn <dje at gcc dot gnu.org> ---
https://gcc.gnu.org/pipermail/gcc/2021-April/235882.html
https://blog.reverberate.org/2021/04/21/musttail-efficient-interpreters.html
The lack of this feature is motivating CPython to rely on LLVM for its JIT in
future releases.
^ permalink raw reply [flat|nested] 34+ messages in thread
* [Bug c/83324] [feature request] Pragma or special syntax for guaranteed tail calls
[not found] <bug-83324-4@http.gcc.gnu.org/bugzilla/>
` (2 preceding siblings ...)
2023-11-16 4:49 ` dje at gcc dot gnu.org
@ 2023-11-16 17:27 ` mikpelinux at gmail dot com
2023-11-16 17:34 ` pinskia at gcc dot gnu.org
` (29 subsequent siblings)
33 siblings, 0 replies; 34+ messages in thread
From: mikpelinux at gmail dot com @ 2023-11-16 17:27 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83324
--- Comment #5 from Mikael Pettersson <mikpelinux at gmail dot com> ---
To get guaranteed tail-calls to work you need to adjust the calling convention
for the caller as well as the callee. Things are trivial as long as parameters
always fit in registers. With parameters on the stack you need, in general, to
shift the responsibility for their deallocation from caller to callee, and this
results in a non-standard calling convention.
^ permalink raw reply [flat|nested] 34+ messages in thread
* [Bug c/83324] [feature request] Pragma or special syntax for guaranteed tail calls
[not found] <bug-83324-4@http.gcc.gnu.org/bugzilla/>
` (3 preceding siblings ...)
2023-11-16 17:27 ` mikpelinux at gmail dot com
@ 2023-11-16 17:34 ` pinskia at gcc dot gnu.org
2023-11-19 17:19 ` pinskia at gcc dot gnu.org
` (28 subsequent siblings)
33 siblings, 0 replies; 34+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-11-16 17:34 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83324
--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to David Edelsohn from comment #4)
> The lack of this feature is motivating CPython to rely on LLVM for its JIT
> in future releases.
Which is interesting because GCC JIT supports this already. Just not exposed to
C. That was mentioned in the gcc mailing list archive that you pointed to too.
e.g.
https://gcc.gnu.org/onlinedocs/jit/topics/expressions.html#c.gcc_jit_rvalue_set_bool_require_tail_call
^ permalink raw reply [flat|nested] 34+ messages in thread
* [Bug c/83324] [feature request] Pragma or special syntax for guaranteed tail calls
[not found] <bug-83324-4@http.gcc.gnu.org/bugzilla/>
` (4 preceding siblings ...)
2023-11-16 17:34 ` pinskia at gcc dot gnu.org
@ 2023-11-19 17:19 ` pinskia at gcc dot gnu.org
2023-11-19 17:23 ` sjames at gcc dot gnu.org
` (27 subsequent siblings)
33 siblings, 0 replies; 34+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-11-19 17:19 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83324
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
See Also| |https://github.com/llvm/llv
| |m-project/issues/72555
--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
https://github.com/llvm/llvm-project/issues/72555
Hmmm
^ permalink raw reply [flat|nested] 34+ messages in thread
* [Bug c/83324] [feature request] Pragma or special syntax for guaranteed tail calls
[not found] <bug-83324-4@http.gcc.gnu.org/bugzilla/>
` (5 preceding siblings ...)
2023-11-19 17:19 ` pinskia at gcc dot gnu.org
@ 2023-11-19 17:23 ` sjames at gcc dot gnu.org
2023-11-20 1:07 ` dje at gcc dot gnu.org
` (26 subsequent siblings)
33 siblings, 0 replies; 34+ messages in thread
From: sjames at gcc dot gnu.org @ 2023-11-19 17:23 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83324
--- Comment #8 from Sam James <sjames at gcc dot gnu.org> ---
(In reply to David Edelsohn from comment #4)
> The lack of this feature is motivating CPython to rely on LLVM for its JIT
> in future releases.
Do you have something I can read up on for this part? It's the first I've heard
it.
^ permalink raw reply [flat|nested] 34+ messages in thread
* [Bug c/83324] [feature request] Pragma or special syntax for guaranteed tail calls
[not found] <bug-83324-4@http.gcc.gnu.org/bugzilla/>
` (6 preceding siblings ...)
2023-11-19 17:23 ` sjames at gcc dot gnu.org
@ 2023-11-20 1:07 ` dje at gcc dot gnu.org
2023-11-20 1:21 ` pinskia at gcc dot gnu.org
` (25 subsequent siblings)
33 siblings, 0 replies; 34+ messages in thread
From: dje at gcc dot gnu.org @ 2023-11-20 1:07 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83324
--- Comment #9 from David Edelsohn <dje at gcc dot gnu.org> ---
Brandt Bucher: A JIT compiler for CPython
https://www.youtube.com/watch?v=HxSHIpEQRjs
https://github.com/brandtbucher/cpython/tree/justin
^ permalink raw reply [flat|nested] 34+ messages in thread
* [Bug c/83324] [feature request] Pragma or special syntax for guaranteed tail calls
[not found] <bug-83324-4@http.gcc.gnu.org/bugzilla/>
` (7 preceding siblings ...)
2023-11-20 1:07 ` dje at gcc dot gnu.org
@ 2023-11-20 1:21 ` pinskia at gcc dot gnu.org
2023-11-20 14:34 ` dje at gcc dot gnu.org
` (24 subsequent siblings)
33 siblings, 0 replies; 34+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-11-20 1:21 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83324
--- Comment #10 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to David Edelsohn from comment #9)
> Brandt Bucher: A JIT compiler for CPython
> https://www.youtube.com/watch?v=HxSHIpEQRjs
> https://github.com/brandtbucher/cpython/tree/justin
But must tail is there for the gcc jit interface already. Maybe it is not
exposed to c/c++ attribute but it is there already. So maybe this is just not
noticing that point.
^ permalink raw reply [flat|nested] 34+ messages in thread
* [Bug c/83324] [feature request] Pragma or special syntax for guaranteed tail calls
[not found] <bug-83324-4@http.gcc.gnu.org/bugzilla/>
` (8 preceding siblings ...)
2023-11-20 1:21 ` pinskia at gcc dot gnu.org
@ 2023-11-20 14:34 ` dje at gcc dot gnu.org
2023-12-25 11:06 ` sjames at gcc dot gnu.org
` (23 subsequent siblings)
33 siblings, 0 replies; 34+ messages in thread
From: dje at gcc dot gnu.org @ 2023-11-20 14:34 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83324
--- Comment #11 from David Edelsohn <dje at gcc dot gnu.org> ---
GIMPLE supports must_tail, but it is not exposed at the sources level /
attributes in GCC.
CPython is not adding the LLVM JIT at runtime. The proposal is to utilize LLVM
at build time to generate code templates that can be copied into the CPython
binary and patched with relocations.
CALL_EXPR_MUST_TAIL_CALL and libgccjit are not sufficient for the CPython plan.
The plan does not propose connecting CPython to an existing JIT in LLVM (or
GCC).
^ permalink raw reply [flat|nested] 34+ messages in thread
* [Bug c/83324] [feature request] Pragma or special syntax for guaranteed tail calls
[not found] <bug-83324-4@http.gcc.gnu.org/bugzilla/>
` (9 preceding siblings ...)
2023-11-20 14:34 ` dje at gcc dot gnu.org
@ 2023-12-25 11:06 ` sjames at gcc dot gnu.org
2024-01-24 11:13 ` sjames at gcc dot gnu.org
` (22 subsequent siblings)
33 siblings, 0 replies; 34+ messages in thread
From: sjames at gcc dot gnu.org @ 2023-12-25 11:06 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83324
Sam James <sjames at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |arsen at gcc dot gnu.org,
| |dmalcolm at gcc dot gnu.org
See Also| |https://gcc.gnu.org/bugzill
| |a/show_bug.cgi?id=110899
--- Comment #12 from Sam James <sjames at gcc dot gnu.org> ---
(In reply to David Edelsohn from comment #11)
> GIMPLE supports must_tail, but it is not exposed at the sources level /
> attributes in GCC.
>
> CPython is not adding the LLVM JIT at runtime. The proposal is to utilize
> LLVM at build time to generate code templates that can be copied into the
> CPython binary and patched with relocations.
This is now up as https://github.com/python/cpython/pull/113465 and
https://github.com/python/cpython/issues/113464.
See also PR110899 and
https://discourse.llvm.org/t/rfc-exposing-ghccc-calling-convention-as-preserve-none-to-clang/74233
(which is linked from the CPython PR for adding the JIT).
^ permalink raw reply [flat|nested] 34+ messages in thread
* [Bug c/83324] [feature request] Pragma or special syntax for guaranteed tail calls
[not found] <bug-83324-4@http.gcc.gnu.org/bugzilla/>
` (10 preceding siblings ...)
2023-12-25 11:06 ` sjames at gcc dot gnu.org
@ 2024-01-24 11:13 ` sjames at gcc dot gnu.org
2024-06-20 5:29 ` andi-gcc at firstfloor dot org
` (21 subsequent siblings)
33 siblings, 0 replies; 34+ messages in thread
From: sjames at gcc dot gnu.org @ 2024-01-24 11:13 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83324
Sam James <sjames at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |andi-gcc at firstfloor dot org
--- Comment #13 from Sam James <sjames at gcc dot gnu.org> ---
Patches posted by Andi Kleen:
https://inbox.sourceware.org/gcc-patches/20240124110800.3154093-2-ak@linux.intel.com/.
^ permalink raw reply [flat|nested] 34+ messages in thread
* [Bug c/83324] [feature request] Pragma or special syntax for guaranteed tail calls
[not found] <bug-83324-4@http.gcc.gnu.org/bugzilla/>
` (11 preceding siblings ...)
2024-01-24 11:13 ` sjames at gcc dot gnu.org
@ 2024-06-20 5:29 ` andi-gcc at firstfloor dot org
2024-07-12 23:16 ` mpolacek at gcc dot gnu.org
` (20 subsequent siblings)
33 siblings, 0 replies; 34+ messages in thread
From: andi-gcc at firstfloor dot org @ 2024-06-20 5:29 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83324
--- Comment #14 from Andi Kleen <andi-gcc at firstfloor dot org> ---
Latest patchkit is here, but stalled due to lack of reviewers:
https://gcc.gnu.org/pipermail/gcc-patches/2024-June/653319.html
^ permalink raw reply [flat|nested] 34+ messages in thread
* [Bug c/83324] [feature request] Pragma or special syntax for guaranteed tail calls
[not found] <bug-83324-4@http.gcc.gnu.org/bugzilla/>
` (12 preceding siblings ...)
2024-06-20 5:29 ` andi-gcc at firstfloor dot org
@ 2024-07-12 23:16 ` mpolacek at gcc dot gnu.org
2024-07-18 4:27 ` cvs-commit at gcc dot gnu.org
` (19 subsequent siblings)
33 siblings, 0 replies; 34+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2024-07-12 23:16 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83324
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |mpolacek at gcc dot gnu.org
Status|NEW |ASSIGNED
^ permalink raw reply [flat|nested] 34+ messages in thread
* [Bug c/83324] [feature request] Pragma or special syntax for guaranteed tail calls
[not found] <bug-83324-4@http.gcc.gnu.org/bugzilla/>
` (13 preceding siblings ...)
2024-07-12 23:16 ` mpolacek at gcc dot gnu.org
@ 2024-07-18 4:27 ` cvs-commit at gcc dot gnu.org
2024-07-18 4:27 ` cvs-commit at gcc dot gnu.org
` (18 subsequent siblings)
33 siblings, 0 replies; 34+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-07-18 4:27 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83324
--- Comment #15 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Andi Kleen <ak@gcc.gnu.org>:
https://gcc.gnu.org/g:a6502accf381358173b19e615fdeb0aa17949c93
commit r15-2122-ga6502accf381358173b19e615fdeb0aa17949c93
Author: Andi Kleen <ak@linux.intel.com>
Date: Tue Jan 23 23:42:08 2024 -0800
Improve must tail in RTL backend
- Give error messages for all causes of non sibling call generation
- When giving error messages clear the musttail flag to avoid ICEs
- Error out when tree-tailcall failed to mark a must-tail call
sibcall. In this case it doesn't know the true reason and only gives
a vague message.
gcc/ChangeLog:
PR c/83324
* calls.cc (maybe_complain_about_tail_call): Clear must tail
flag on error.
(expand_call): Give error messages for all musttail failures.
^ permalink raw reply [flat|nested] 34+ messages in thread
* [Bug c/83324] [feature request] Pragma or special syntax for guaranteed tail calls
[not found] <bug-83324-4@http.gcc.gnu.org/bugzilla/>
` (14 preceding siblings ...)
2024-07-18 4:27 ` cvs-commit at gcc dot gnu.org
@ 2024-07-18 4:27 ` cvs-commit at gcc dot gnu.org
2024-07-18 4:27 ` cvs-commit at gcc dot gnu.org
` (17 subsequent siblings)
33 siblings, 0 replies; 34+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-07-18 4:27 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83324
--- Comment #16 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Andi Kleen <ak@gcc.gnu.org>:
https://gcc.gnu.org/g:b738a63e528db410a1c51fc27db37fe22f0cb397
commit r15-2124-gb738a63e528db410a1c51fc27db37fe22f0cb397
Author: Andi Kleen <ak@linux.intel.com>
Date: Wed May 15 19:57:22 2024 -0700
Enable musttail tail conversion even when not optimizing
Enable the tailcall optimization for non optimizing builds,
but in this case only checks calls that have the musttail attribute set.
This makes musttail work without optimization.
This is done with a new late musttail pass that is only active when
not optimizing. The new pass relies on tree-cfg to discover musttails.
This avoids a ~0.8% compiler run time penalty at -O0.
gcc/ChangeLog:
PR c/83324
* function.h (struct function): Add has_musttail.
* lto-streamer-in.cc (input_struct_function_base): Stream
has_musttail.
* lto-streamer-out.cc (output_struct_function_base): Dito.
* passes.def (pass_musttail): Add.
* tree-cfg.cc (notice_special_calls): Record has_musttail.
(clear_special_calls): Clear has_musttail.
* tree-pass.h (make_pass_musttail): Add.
* tree-tailcall.cc (find_tail_calls): Handle only_musttail
argument.
(tree_optimize_tail_calls_1): Pass on only_musttail.
(execute_tail_calls): Pass only_musttail as false.
(class pass_musttail): Add.
(make_pass_musttail): Add.
^ permalink raw reply [flat|nested] 34+ messages in thread
* [Bug c/83324] [feature request] Pragma or special syntax for guaranteed tail calls
[not found] <bug-83324-4@http.gcc.gnu.org/bugzilla/>
` (15 preceding siblings ...)
2024-07-18 4:27 ` cvs-commit at gcc dot gnu.org
@ 2024-07-18 4:27 ` cvs-commit at gcc dot gnu.org
2024-07-18 4:27 ` cvs-commit at gcc dot gnu.org
` (16 subsequent siblings)
33 siblings, 0 replies; 34+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-07-18 4:27 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83324
--- Comment #17 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Andi Kleen <ak@gcc.gnu.org>:
https://gcc.gnu.org/g:81824596361cf4919d6dc026155160581c99b860
commit r15-2125-g81824596361cf4919d6dc026155160581c99b860
Author: Andi Kleen <ak@linux.intel.com>
Date: Tue May 21 07:01:57 2024 -0700
Give better error messages for musttail
When musttail is set, make tree-tailcall give error messages
when it cannot handle a call. This avoids vague "other reasons"
error messages later at expand time when it sees a musttail
function not marked tail call.
In various cases this requires delaying the error until
the call is discovered.
Also print more information on the failure to the dump file.
gcc/ChangeLog:
PR c/83324
* tree-tailcall.cc (maybe_error_musttail): New function.
(suitable_for_tail_opt_p): Report error reason.
(suitable_for_tail_call_opt_p): Report error reason.
(find_tail_calls): Accept basic blocks with abnormal edges.
Delay reporting of errors until the call is discovered.
Move top level suitability checks to here.
(tree_optimize_tail_calls_1): Remove top level checks.
^ permalink raw reply [flat|nested] 34+ messages in thread
* [Bug c/83324] [feature request] Pragma or special syntax for guaranteed tail calls
[not found] <bug-83324-4@http.gcc.gnu.org/bugzilla/>
` (16 preceding siblings ...)
2024-07-18 4:27 ` cvs-commit at gcc dot gnu.org
@ 2024-07-18 4:27 ` cvs-commit at gcc dot gnu.org
2024-07-18 15:34 ` andi-gcc at firstfloor dot org
` (15 subsequent siblings)
33 siblings, 0 replies; 34+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-07-18 4:27 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83324
--- Comment #18 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Andi Kleen <ak@gcc.gnu.org>:
https://gcc.gnu.org/g:d062b0abf45cd54057352fc4b7827a3b1b9a160a
commit r15-2126-gd062b0abf45cd54057352fc4b7827a3b1b9a160a
Author: Andi Kleen <ak@linux.intel.com>
Date: Fri Jun 21 11:19:12 2024 -0700
Mark expand musttail error messages for translation
The musttail error messages are reported to the user, so must be
translated.
gcc/ChangeLog:
PR c/83324
* calls.cc (initialize_argument_information): Mark messages
for translation.
(can_implement_as_sibling_call_p): Dito.
(expand_call): Dito.
^ permalink raw reply [flat|nested] 34+ messages in thread
* [Bug c/83324] [feature request] Pragma or special syntax for guaranteed tail calls
[not found] <bug-83324-4@http.gcc.gnu.org/bugzilla/>
` (17 preceding siblings ...)
2024-07-18 4:27 ` cvs-commit at gcc dot gnu.org
@ 2024-07-18 15:34 ` andi-gcc at firstfloor dot org
2024-07-20 6:34 ` cvs-commit at gcc dot gnu.org
` (14 subsequent siblings)
33 siblings, 0 replies; 34+ messages in thread
From: andi-gcc at firstfloor dot org @ 2024-07-18 15:34 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83324
--- Comment #19 from Andi Kleen <andi-gcc at firstfloor dot org> ---
Middle/back-end parts are in, still need acks for the C/C++ frontend parts
^ permalink raw reply [flat|nested] 34+ messages in thread
* [Bug c/83324] [feature request] Pragma or special syntax for guaranteed tail calls
[not found] <bug-83324-4@http.gcc.gnu.org/bugzilla/>
` (18 preceding siblings ...)
2024-07-18 15:34 ` andi-gcc at firstfloor dot org
@ 2024-07-20 6:34 ` cvs-commit at gcc dot gnu.org
2024-07-20 6:34 ` cvs-commit at gcc dot gnu.org
` (13 subsequent siblings)
33 siblings, 0 replies; 34+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-07-20 6:34 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83324
--- Comment #20 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Andi Kleen <ak@gcc.gnu.org>:
https://gcc.gnu.org/g:5c4c1fe6df0f752764cdfd7404a60bfd2b4f5057
commit r15-2168-g5c4c1fe6df0f752764cdfd7404a60bfd2b4f5057
Author: Andi Kleen <ak@linux.intel.com>
Date: Wed May 15 19:38:43 2024 -0700
Add a musttail generic attribute to the c-attribs table
The actual handling is directly in the parser since the
generic mechanism doesn't support statement attributes,
but this gives basic error checking/detection on the attribute.
gcc/c-family/ChangeLog:
PR c/83324
* c-attribs.cc (handle_musttail_attribute): Add.
* c-common.h (handle_musttail_attribute): Add.
^ permalink raw reply [flat|nested] 34+ messages in thread
* [Bug c/83324] [feature request] Pragma or special syntax for guaranteed tail calls
[not found] <bug-83324-4@http.gcc.gnu.org/bugzilla/>
` (19 preceding siblings ...)
2024-07-20 6:34 ` cvs-commit at gcc dot gnu.org
@ 2024-07-20 6:34 ` cvs-commit at gcc dot gnu.org
2024-07-20 6:34 ` cvs-commit at gcc dot gnu.org
` (12 subsequent siblings)
33 siblings, 0 replies; 34+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-07-20 6:34 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83324
--- Comment #21 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Andi Kleen <ak@gcc.gnu.org>:
https://gcc.gnu.org/g:59dd1d7ab21ad9a7ebf641ec9aeea609c003ad2f
commit r15-2169-g59dd1d7ab21ad9a7ebf641ec9aeea609c003ad2f
Author: Andi Kleen <ak@linux.intel.com>
Date: Tue Jan 23 23:44:48 2024 -0800
C++: Support clang compatible [[musttail]] (PR83324)
This patch implements a clang compatible [[musttail]] attribute for
returns.
musttail is useful as an alternative to computed goto for interpreters.
With computed goto the interpreter function usually ends up very big
which causes problems with register allocation and other per function
optimizations not scaling. With musttail the interpreter can be instead
written as a sequence of smaller functions that call each other. To
avoid unbounded stack growth this requires forcing a sibling call, which
this attribute does. It guarantees an error if the call cannot be tail
called which allows the programmer to fix it instead of risking a stack
overflow. Unlike computed goto it is also type-safe.
It turns out that David Malcolm had already implemented middle/backend
support for a musttail attribute back in 2016, but it wasn't exposed
to any frontend other than a special plugin.
This patch adds a [[gnu::musttail]] attribute for C++ that can be added
to return statements. The return statement must be a direct call
(it does not follow dependencies), which is similar to what clang
implements. It then uses the existing must tail infrastructure.
For compatibility it also detects clang::musttail
Passes bootstrap and full test
gcc/c-family/ChangeLog:
* c-attribs.cc (set_musttail_on_return): New function.
* c-common.h (set_musttail_on_return): Declare new function.
gcc/cp/ChangeLog:
PR c/83324
* cp-tree.h (AGGR_INIT_EXPR_MUST_TAIL): Add.
* parser.cc (cp_parser_statement): Handle musttail.
(cp_parser_jump_statement): Dito.
* pt.cc (tsubst_expr): Copy CALL_EXPR_MUST_TAIL_CALL.
* semantics.cc (simplify_aggr_init_expr): Handle musttail.
^ permalink raw reply [flat|nested] 34+ messages in thread
* [Bug c/83324] [feature request] Pragma or special syntax for guaranteed tail calls
[not found] <bug-83324-4@http.gcc.gnu.org/bugzilla/>
` (20 preceding siblings ...)
2024-07-20 6:34 ` cvs-commit at gcc dot gnu.org
@ 2024-07-20 6:34 ` cvs-commit at gcc dot gnu.org
2024-07-20 6:34 ` cvs-commit at gcc dot gnu.org
` (11 subsequent siblings)
33 siblings, 0 replies; 34+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-07-20 6:34 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83324
--- Comment #22 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Andi Kleen <ak@gcc.gnu.org>:
https://gcc.gnu.org/g:7db47f7b915c5f5d645fa536547e26b92290afe3
commit r15-2170-g7db47f7b915c5f5d645fa536547e26b92290afe3
Author: Andi Kleen <ak@linux.intel.com>
Date: Wed Jan 24 07:44:23 2024 -0800
C: Implement musttail attribute for returns
Implement a C23 clang compatible musttail attribute similar to the earlier
C++ implementation in the C parser.
gcc/c/ChangeLog:
PR c/83324
* c-parser.cc (struct attr_state): Define with musttail_p.
(c_parser_statement_after_labels): Handle [[musttail]].
(c_parser_std_attribute): Dito.
(c_parser_handle_musttail): Dito.
(c_parser_compound_statement_nostart): Dito.
(c_parser_all_labels): Dito.
(c_parser_statement): Dito.
* c-tree.h (c_finish_return): Add musttail_p flag.
* c-typeck.cc (c_finish_return): Handle musttail_p flag.
^ permalink raw reply [flat|nested] 34+ messages in thread
* [Bug c/83324] [feature request] Pragma or special syntax for guaranteed tail calls
[not found] <bug-83324-4@http.gcc.gnu.org/bugzilla/>
` (21 preceding siblings ...)
2024-07-20 6:34 ` cvs-commit at gcc dot gnu.org
@ 2024-07-20 6:34 ` cvs-commit at gcc dot gnu.org
2024-07-23 20:28 ` cvs-commit at gcc dot gnu.org
` (10 subsequent siblings)
33 siblings, 0 replies; 34+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-07-20 6:34 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83324
--- Comment #23 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Andi Kleen <ak@gcc.gnu.org>:
https://gcc.gnu.org/g:56f824cc206ff00d466aaeb11211d8005c4668bc
commit r15-2172-g56f824cc206ff00d466aaeb11211d8005c4668bc
Author: Andi Kleen <ak@linux.intel.com>
Date: Tue Jan 23 23:38:23 2024 -0800
Add documentation for musttail attribute
gcc/ChangeLog:
PR c/83324
* doc/extend.texi: Document [[musttail]]
^ permalink raw reply [flat|nested] 34+ messages in thread
* [Bug c/83324] [feature request] Pragma or special syntax for guaranteed tail calls
[not found] <bug-83324-4@http.gcc.gnu.org/bugzilla/>
` (22 preceding siblings ...)
2024-07-20 6:34 ` cvs-commit at gcc dot gnu.org
@ 2024-07-23 20:28 ` cvs-commit at gcc dot gnu.org
2024-07-23 20:28 ` cvs-commit at gcc dot gnu.org
` (9 subsequent siblings)
33 siblings, 0 replies; 34+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-07-23 20:28 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83324
--- Comment #24 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Andi Kleen <ak@gcc.gnu.org>:
https://gcc.gnu.org/g:2bd8177256b6d87f6e75819218cf22c2c0bfc1ac
commit r15-2231-g2bd8177256b6d87f6e75819218cf22c2c0bfc1ac
Author: Andi Kleen <ak@linux.intel.com>
Date: Tue Jan 23 23:44:48 2024 -0800
C++: Support clang compatible [[musttail]] (PR83324)
This patch implements a clang compatible [[musttail]] attribute for
returns.
musttail is useful as an alternative to computed goto for interpreters.
With computed goto the interpreter function usually ends up very big
which causes problems with register allocation and other per function
optimizations not scaling. With musttail the interpreter can be instead
written as a sequence of smaller functions that call each other. To
avoid unbounded stack growth this requires forcing a sibling call, which
this attribute does. It guarantees an error if the call cannot be tail
called which allows the programmer to fix it instead of risking a stack
overflow. Unlike computed goto it is also type-safe.
It turns out that David Malcolm had already implemented middle/backend
support for a musttail attribute back in 2016, but it wasn't exposed
to any frontend other than a special plugin.
This patch adds a [[gnu::musttail]] attribute for C++ that can be added
to return statements. The return statement must be a direct call
(it does not follow dependencies), which is similar to what clang
implements. It then uses the existing must tail infrastructure.
For compatibility it also detects clang::musttail
Passes bootstrap and full test
gcc/c-family/ChangeLog:
* c-attribs.cc (set_musttail_on_return): New function.
* c-common.h (set_musttail_on_return): Declare new function.
gcc/cp/ChangeLog:
PR c/83324
* cp-tree.h (AGGR_INIT_EXPR_MUST_TAIL): Add.
* parser.cc (cp_parser_statement): Handle musttail.
(cp_parser_jump_statement): Dito.
* pt.cc (tsubst_expr): Copy CALL_EXPR_MUST_TAIL_CALL.
* semantics.cc (simplify_aggr_init_expr): Handle musttail.
^ permalink raw reply [flat|nested] 34+ messages in thread
* [Bug c/83324] [feature request] Pragma or special syntax for guaranteed tail calls
[not found] <bug-83324-4@http.gcc.gnu.org/bugzilla/>
` (23 preceding siblings ...)
2024-07-23 20:28 ` cvs-commit at gcc dot gnu.org
@ 2024-07-23 20:28 ` cvs-commit at gcc dot gnu.org
2024-07-23 20:28 ` cvs-commit at gcc dot gnu.org
` (8 subsequent siblings)
33 siblings, 0 replies; 34+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-07-23 20:28 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83324
--- Comment #24 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Andi Kleen <ak@gcc.gnu.org>:
https://gcc.gnu.org/g:2bd8177256b6d87f6e75819218cf22c2c0bfc1ac
commit r15-2231-g2bd8177256b6d87f6e75819218cf22c2c0bfc1ac
Author: Andi Kleen <ak@linux.intel.com>
Date: Tue Jan 23 23:44:48 2024 -0800
C++: Support clang compatible [[musttail]] (PR83324)
This patch implements a clang compatible [[musttail]] attribute for
returns.
musttail is useful as an alternative to computed goto for interpreters.
With computed goto the interpreter function usually ends up very big
which causes problems with register allocation and other per function
optimizations not scaling. With musttail the interpreter can be instead
written as a sequence of smaller functions that call each other. To
avoid unbounded stack growth this requires forcing a sibling call, which
this attribute does. It guarantees an error if the call cannot be tail
called which allows the programmer to fix it instead of risking a stack
overflow. Unlike computed goto it is also type-safe.
It turns out that David Malcolm had already implemented middle/backend
support for a musttail attribute back in 2016, but it wasn't exposed
to any frontend other than a special plugin.
This patch adds a [[gnu::musttail]] attribute for C++ that can be added
to return statements. The return statement must be a direct call
(it does not follow dependencies), which is similar to what clang
implements. It then uses the existing must tail infrastructure.
For compatibility it also detects clang::musttail
Passes bootstrap and full test
gcc/c-family/ChangeLog:
* c-attribs.cc (set_musttail_on_return): New function.
* c-common.h (set_musttail_on_return): Declare new function.
gcc/cp/ChangeLog:
PR c/83324
* cp-tree.h (AGGR_INIT_EXPR_MUST_TAIL): Add.
* parser.cc (cp_parser_statement): Handle musttail.
(cp_parser_jump_statement): Dito.
* pt.cc (tsubst_expr): Copy CALL_EXPR_MUST_TAIL_CALL.
* semantics.cc (simplify_aggr_init_expr): Handle musttail.
--- Comment #25 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Andi Kleen <ak@gcc.gnu.org>:
https://gcc.gnu.org/g:78bbdbd5352df527feccf0a8c2f862f25a2e88b4
commit r15-2232-g78bbdbd5352df527feccf0a8c2f862f25a2e88b4
Author: Andi Kleen <ak@linux.intel.com>
Date: Wed Jan 24 07:44:23 2024 -0800
C: Implement musttail attribute for returns
Implement a C23 clang compatible musttail attribute similar to the earlier
C++ implementation in the C parser.
gcc/c/ChangeLog:
PR c/83324
* c-parser.cc (struct attr_state): Define with musttail_p.
(c_parser_statement_after_labels): Handle [[musttail]].
(c_parser_std_attribute): Dito.
(c_parser_handle_musttail): Dito.
(c_parser_compound_statement_nostart): Dito.
(c_parser_all_labels): Dito.
(c_parser_statement): Dito.
* c-tree.h (c_finish_return): Add musttail_p flag.
* c-typeck.cc (c_finish_return): Handle musttail_p flag.
^ permalink raw reply [flat|nested] 34+ messages in thread
* [Bug c/83324] [feature request] Pragma or special syntax for guaranteed tail calls
[not found] <bug-83324-4@http.gcc.gnu.org/bugzilla/>
` (24 preceding siblings ...)
2024-07-23 20:28 ` cvs-commit at gcc dot gnu.org
@ 2024-07-23 20:28 ` cvs-commit at gcc dot gnu.org
2024-07-23 21:10 ` ak at gcc dot gnu.org
` (7 subsequent siblings)
33 siblings, 0 replies; 34+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-07-23 20:28 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83324
--- Comment #26 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Andi Kleen <ak@gcc.gnu.org>:
https://gcc.gnu.org/g:8daae81113eeff37b4ae2e08a9797295fbc8b81e
commit r15-2234-g8daae81113eeff37b4ae2e08a9797295fbc8b81e
Author: Andi Kleen <ak@linux.intel.com>
Date: Tue Jan 23 23:38:23 2024 -0800
Add documentation for musttail attribute
gcc/ChangeLog:
PR c/83324
* doc/extend.texi: Document [[musttail]]
^ permalink raw reply [flat|nested] 34+ messages in thread
* [Bug c/83324] [feature request] Pragma or special syntax for guaranteed tail calls
[not found] <bug-83324-4@http.gcc.gnu.org/bugzilla/>
` (25 preceding siblings ...)
2024-07-23 20:28 ` cvs-commit at gcc dot gnu.org
@ 2024-07-23 21:10 ` ak at gcc dot gnu.org
2024-08-21 21:31 ` lucier at math dot purdue.edu
` (6 subsequent siblings)
33 siblings, 0 replies; 34+ messages in thread
From: ak at gcc dot gnu.org @ 2024-07-23 21:10 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83324
ak at gcc dot gnu.org changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
CC| |ak at gcc dot gnu.org
Status|ASSIGNED |RESOLVED
--- Comment #27 from ak at gcc dot gnu.org ---
Implemented in trunk in a mostly LLVM compatible way. There are some remaining
open issues (PR116019, PR115979, PR115606, PR115607) , but none should be show
stoppers.
There are some differences to clang, mainly that gcc handles a few cases that
clang doesn't, but clang handles more cases with -O0. The success also depends
on the architecture and the languages (C is better than C++ due to PR115606)
^ permalink raw reply [flat|nested] 34+ messages in thread
* [Bug c/83324] [feature request] Pragma or special syntax for guaranteed tail calls
[not found] <bug-83324-4@http.gcc.gnu.org/bugzilla/>
` (26 preceding siblings ...)
2024-07-23 21:10 ` ak at gcc dot gnu.org
@ 2024-08-21 21:31 ` lucier at math dot purdue.edu
2024-08-22 16:32 ` andi at firstfloor dot org
` (5 subsequent siblings)
33 siblings, 0 replies; 34+ messages in thread
From: lucier at math dot purdue.edu @ 2024-08-21 21:31 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83324
lucier at math dot purdue.edu changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |lucier at math dot purdue.edu
--- Comment #28 from lucier at math dot purdue.edu ---
I'd like to ask whether this new attribute replaces or otherwise interacts with
the existing -foptimize-sibling-calls flag. Thanks. Brad
^ permalink raw reply [flat|nested] 34+ messages in thread
* [Bug c/83324] [feature request] Pragma or special syntax for guaranteed tail calls
[not found] <bug-83324-4@http.gcc.gnu.org/bugzilla/>
` (27 preceding siblings ...)
2024-08-21 21:31 ` lucier at math dot purdue.edu
@ 2024-08-22 16:32 ` andi at firstfloor dot org
2024-08-23 17:45 ` lucier at math dot purdue.edu
` (4 subsequent siblings)
33 siblings, 0 replies; 34+ messages in thread
From: andi at firstfloor dot org @ 2024-08-22 16:32 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83324
--- Comment #29 from andi at firstfloor dot org ---
The semantics of -foptimize-sibling-calls do not change. However if your
program depends on sbling calls for correctness it should migrate to the
new attribute
^ permalink raw reply [flat|nested] 34+ messages in thread
* [Bug c/83324] [feature request] Pragma or special syntax for guaranteed tail calls
[not found] <bug-83324-4@http.gcc.gnu.org/bugzilla/>
` (28 preceding siblings ...)
2024-08-22 16:32 ` andi at firstfloor dot org
@ 2024-08-23 17:45 ` lucier at math dot purdue.edu
2024-08-25 1:39 ` lucier at math dot purdue.edu
` (3 subsequent siblings)
33 siblings, 0 replies; 34+ messages in thread
From: lucier at math dot purdue.edu @ 2024-08-23 17:45 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83324
--- Comment #30 from lucier at math dot purdue.edu ---
Thanks.
I asked for some help in testing this new attribute at gcc-help:
https://gcc.gnu.org/pipermail/gcc-help/2024-August/143676.html
^ permalink raw reply [flat|nested] 34+ messages in thread
* [Bug c/83324] [feature request] Pragma or special syntax for guaranteed tail calls
[not found] <bug-83324-4@http.gcc.gnu.org/bugzilla/>
` (29 preceding siblings ...)
2024-08-23 17:45 ` lucier at math dot purdue.edu
@ 2024-08-25 1:39 ` lucier at math dot purdue.edu
2024-08-25 22:08 ` andi at firstfloor dot org
` (2 subsequent siblings)
33 siblings, 0 replies; 34+ messages in thread
From: lucier at math dot purdue.edu @ 2024-08-25 1:39 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83324
--- Comment #31 from lucier at math dot purdue.edu ---
Are there plans to support the __attribute__((musttail)) notation for C code?
It appears that with
heine:~/programs/gambit/gambit> clang -v
Ubuntu clang version 14.0.0-1ubuntu1.1
one needs to pass something like -std=c2x on the command line to support
[[clang::musttail]], while this clang supports __attribute__((musttail)) "out
of the box", as it were.
^ permalink raw reply [flat|nested] 34+ messages in thread
* [Bug c/83324] [feature request] Pragma or special syntax for guaranteed tail calls
[not found] <bug-83324-4@http.gcc.gnu.org/bugzilla/>
` (30 preceding siblings ...)
2024-08-25 1:39 ` lucier at math dot purdue.edu
@ 2024-08-25 22:08 ` andi at firstfloor dot org
2024-08-26 0:25 ` lucier at math dot purdue.edu
2024-09-04 15:07 ` egallager at gcc dot gnu.org
33 siblings, 0 replies; 34+ messages in thread
From: andi at firstfloor dot org @ 2024-08-25 22:08 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83324
--- Comment #32 from andi at firstfloor dot org ---
The feature is currently only supported with standard C/C++ attributes
([[clang/gnu::musttail]]), not __attribute__
But given that you have existing code that uses the old syntax
and clang supports that too we should probably add that too.
^ permalink raw reply [flat|nested] 34+ messages in thread
* [Bug c/83324] [feature request] Pragma or special syntax for guaranteed tail calls
[not found] <bug-83324-4@http.gcc.gnu.org/bugzilla/>
` (31 preceding siblings ...)
2024-08-25 22:08 ` andi at firstfloor dot org
@ 2024-08-26 0:25 ` lucier at math dot purdue.edu
2024-09-04 15:07 ` egallager at gcc dot gnu.org
33 siblings, 0 replies; 34+ messages in thread
From: lucier at math dot purdue.edu @ 2024-08-26 0:25 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83324
--- Comment #33 from lucier at math dot purdue.edu ---
I don't know what the issues are about whether to support __attribute__,
whether the notation is obsolete or nonstandard.
If gcc doesn't support this notation, it might lead to just one more #ifdef in
the user code.
^ permalink raw reply [flat|nested] 34+ messages in thread
* [Bug c/83324] [feature request] Pragma or special syntax for guaranteed tail calls
[not found] <bug-83324-4@http.gcc.gnu.org/bugzilla/>
` (32 preceding siblings ...)
2024-08-26 0:25 ` lucier at math dot purdue.edu
@ 2024-09-04 15:07 ` egallager at gcc dot gnu.org
33 siblings, 0 replies; 34+ messages in thread
From: egallager at gcc dot gnu.org @ 2024-09-04 15:07 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83324
--- Comment #34 from Eric Gallager <egallager at gcc dot gnu.org> ---
Yeah I think GCC should support the __attribute__ style syntax for this
attribute, too
^ permalink raw reply [flat|nested] 34+ messages in thread