llvm-project
43d83c3b - [clang][CodeGen] Emit return after musttail call to noreturn function

Commit
28 days ago
[clang][CodeGen] Emit return after musttail call to noreturn function A musttail call to a noreturn function (`__attribute__((noreturn))`, `_Noreturn`, `exit()`, `longjmp()`, ...) gets `unreachable` after it instead of `ret`, which fails the verifier with "musttail call must precede a ret". Release builds skip the verifier, so -O2 crashes with "failed to perform tail call elimination on a call site marked musttail" and -O0 silently emits a regular call. Sema only rejects `[[noreturn]]` callees (#77727), so all other spellings get through. Implicit musttail calls produce the same invalid IR: `swiftasynccall`, and the `-fptrauth-calls` thunk for a pointer to a noreturn virtual member function. The latter crashes even at -O0, without any `musttail` in the source. The noreturn path in `EmitCall` runs before the musttail one. This patch skips it for musttail calls, so they get a `ret` like any other musttail call. As a side effect, the musttail checks there (e.g. the noexcept mismatch error) now apply to noreturn callees too. This matches GCC, which accepts musttail calls to noreturn functions, `[[noreturn]]` ones included: https://godbolt.org/z/q8ajhMh15 With CodeGen handling it, the Sema error for `[[noreturn]]` callees is no longer needed. I'll lift it in a follow-up PR. Inspired by rnk's comment in #191198 asking whether the thunk code emitting a `ret` after the musttail call is dead: https://github.com/llvm/llvm-project/pull/191198#discussion_r3414988237. Only noreturn callees reach it. Fixes #60162. Fixes #120088. Fixes #120637.
Author
Committer
Parents
Loading