Why noreturn/__builtin_unreachable prevents tail call optimization

后端 未结 1 1848
无人共我
无人共我 2021-01-13 08:37

I have come to fact that all major compilers will not do tail call optimization if a called function does not return (i.e. marked as _Noreturn/[[noreturn]

相关标签:
1条回答
  • 2021-01-13 09:08

    It's intentional, though perhaps controversial since it can seriously harm stack usage properties; for this reason I've even resorted to tricking the compiler to think a function that can't return can. The reasoning is that many noreturn functions are abort-like (or even call abort), and that it's likely someone running a debugger wants to be able to see where the call happened from -- information which would be lost by a tail call.

    Citations:

    • https://gcc.gnu.org/bugzilla/show_bug.cgi?id=10837
    • https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56165
    • https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67327
    • etc.
    0 讨论(0)
提交回复
热议问题