"musttail" statement attribute for GCC?

Josh Haberman jhaberman@gmail.com
Fri Apr 23 21:13:16 GMT 2021


David Malcolm via Gcc <gcc@gcc.gnu.org> wrote:
> FWIW I implemented something like this in GCC's middle-end here:
> https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=9a385c2d3d74ffed78f2ed9ad47b844d2f294105
> exposing it in API form for libgccjit:
> https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=15c671a79ca66df5b1de70dd1a0b78414fe003ef
> https://gcc.gnu.org/onlinedocs/jit/topics/expressions.html#c.gcc_jit_rvalue_set_bool_require_tail_call
> but IIRC it's not yet exposed to the regular GCC frontends.

That's great to hear that there is some existing infrastructure around this.

Your code includes some checks that we should consider adding to Clang
(especially the check against "returns twice"). Why the prohibition
against noreturn though? I've found that tail calls to noreturn
functions are useful for longjmp()-based error handling, and musttail
could be a useful workaround for
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=10837#c2.

On Fri, Apr 23, 2021 at 1:10 PM Iain Sandoe <idsandoe@googlemail.com> wrote:
> I did try to use it this ^ for GCC coroutines (where such a guarantee is
> pretty important)
>
> However, the issue there is that not all targets support indirect tailcalls.

I'm not familiar with this limitation. What targets do not support
indirect tail calls?

> What about tailcalls between DSOs?

What issues are there around DSOs? Clang/LLVM don't treat these
specially AFAIK, and it seems that tail calls through a PLT should
work okay?

Thanks,
Josh


More information about the Gcc mailing list