Search code examples
cclangtail-call-optimization

Is it possible to force tail call optimization on GCC/Clang?


I'm trying to write a program in functional style with C as much as possible. I know fine compilers like GCC/Clang do tail call optimization silently, but it's not guaranteed. Is there any option to force tail call optimization on the compilers? (Of course when only it's called at the end of itself)


Solution

  • Clang is not doing any optimisations at all. There is an LLVM pass tailcallelim which may do what you want (but it is not guaranteed). You can run it separately with opt.