Re: CALL_EXPR_MUST_TAIL_CALL and LLVM's musttail

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





On 12/9/2021 6:06 PM, Marc Feeley wrote:
On Dec 9, 2021, at 6:36 PM, Segher Boessenkool <segher@xxxxxxxxxxxxxxxxxxx> wrote:

The code generated by the Gambit compiler is sufficiently complex that it would be impossible (in the halting problem sense) to check that the tail-calling constraints are not violated. However, I know the constraints are not violated because the code was designed that way. And if I’m mistaken in this belief, then I am the one that will bare the blame of the ensuing problems.
On most architectures you can simply check if there are any "return"
instructions generated, no?  Or do you generate any actual calls (to
user code) as well?

You mean a “return” at the assembly code level?  Seems very brittle… on x86 a “pop %eax; jmp *%eax” will do the same as a “ret” and gcc might generate that sequence (from my point of view).
It might generate something horrible like that for retpolines, but for normal code that kind of sequence would be awful for performance (it'll mess up the call/return predictor stack) and terrible for security (it's a ROP gadget).





  In any case, as I said previously, I don’t want to check if gcc did not optimize the tail calls… it is too late to do anything other than essentially tell the programmer “sorry I couldn’t compile that program correctly”.
We don't generally like that kind of diagnostic particularly from the code generator.  If it's valid C code, then we need to generate correct target code.

So what I need is some way to test at compile time if for the target architecture and compile options there is a guarantee that tail calls will be optimized (if the C code obeys the usual set of constraints).  Something like

   #if __has_attribute(tail_call_supported_on_this_architecture)
   /* use tail calls for jumping around... */
   #else
   /* use trampoline fallback... */
   #endif
Which is the fundamental problem.  GCC simply doesn't have the concept that "this must be implemented as a tail call".

You might want to touch base with Iain Sandoe though.  I vaguely remember this coming up in the context of coroutines.

jeff



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux