https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111786
Bug ID: 111786 Summary: No tail recursion for simple program Product: gcc Version: 13.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: lukas.gra...@tu-darmstadt.de Target Milestone: --- Created attachment 56096 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=56096&action=edit C code of expr_main Follow up with nearly the same source file as 111643, only without the flatten attribute. Sorry for taking so long for that. I learned the optimized compiler should output a tail recursion. But this seams not to be the case: With "sub" and "call", 16 bytes on the stack are used. The file attached file contains: --- int expr_main(int argc, char **argv) { return expr_main_original(argc, argv); } --- And after cc1 -O3 on amd64, the output contains: -- gcc 13.2.0 -- expr_main: subq $8, %rsp call expr_main_original --- -- gcc 9.4.0 shipped with ubuntu 20.04 --- expr_main: endbr64 pushq %rax popq %rax pushq %rax call expr_main_original --- -- Expected -- expr_main: jmp expr_main_original --- If I compile the above snippet only, I get the expected result. But not when compiling the whole C file which also includes the body of expr_main_original(). I also suspect there are some other factors I don't know, since many other functions I tested yield the expected result. In my case, the overhead seams to be negligible. However, I think it should be possible to construct similar recursive programs where the overhead compared to tail recursion is not negligible.