Re: CALL_EXPR_MUST_TAIL_CALL and LLVM's musttail

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

 



* Bradley Lucier via Gcc-help:

> Here's the kind of call I'd like turned into a tail call:
>
> return (*((___host*)((((long*)((___pc)-(1))) + (1 +((-2)))))))(___ps);
>
> and it appears that gcc doesn't want to convert it to a tail call.
> The calling function has the same argument sequence.
>
> What should I search for in the .s file to see if this was tail
> called?   It appears that the assembly code that this is translated
> into is:
>
> <stuff removed>
> 	movq	-864(%rbp), %rax
> 	subq	$9, %rax
> 	.loc 1 95837 157
> 	movq	(%rax), %rdx
> 	movq	-1032(%rbp), %rax
> 	movq	%rax, %rdi
> 	call	*%rdx
> .LVL0:
> .L1:
> 	.loc 1 95837 220
> 	movq	-24(%rbp), %rax
> 	subq	%fs:40, %rax
> 	je	.L17743
> 	call	__stack_chk_fail@PLT
> .L17743:
> 	movq	-8(%rbp), %rbx
> 	leave
> 	.cfi_def_cfa 7, 8
> 	ret

The stack guard suggests that there addressable variables on the stack.
Maybe GCC cannot prove that the arguments in the tail call cannot be
used to access those stack variables?

> PS:  LLVM seems to have a musttail attribute that you use at the call site:
>
> -#define ___PROPER_TAIL_CALL(call) __attribute__((musttail)) return call
>
> Does gcc have something like that?

There was a discussion about this in April:

  "musttail" statement attribute for GCC?
  <https://gcc.gnu.org/pipermail/gcc/2021-April/235882.html>

Some ABIs make tail-calls hard, and they are not always an optimization.

Thanks,
Florian




[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