Skip to content

clang rejects a musttail call when it's perfectly fine to tail call #164312

@ahatanak

Description

@ahatanak

$ cat test.cpp

void foobar() noexcept;

void dance() noexcept {
#ifdef MUSTTAIL
  [[clang::musttail]]
#endif
  return foobar();
}
$ clang++ -std=c++20 -c -o /dev/null -DMUSTTAIL test.cpp
test.cpp:7:9: error: cannot compile this tail call skipping over cleanups yet
    7 |         return foobar();
      |                ^~~~~~~~
1 error generated.

The attempt to tail call fails because the caller (dance) is marked as noexcept, which causes EHTerminateScope to be pushed onto the EHStack.

I think clang should be able to do the tail call as there's no cleanup code that has to be emitted after the call in this case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:codegenIR generation bugs: mangling, exceptions, etc.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions