Issue |
151581
|
Summary |
`[[musttail]]` Silently ignored in some cases in conjuction with the `flatten` attribute
|
Labels |
new issue
|
Assignees |
|
Reporter |
Hendiadyoin1
|
In <https://github.com/LadybirdBrowser/ladybird/pull/5641>
I have found that `[[musttail]]` is silently ignored in some cases.
To describe what the linked code does
It moves a jump-threading bytecode interpreter to a similar model, trying to do tail-calls to member pointers instead,
each dispatch function is flattened to squeeze out a bit more performance, yielding:
```c++
#define DISPATCH_NEXT() \
do { \
auto& next_instruction = *reinterpret_cast<Instruction const*>(&bytecode[program_counter]); \
auto fn = dispatch_instruction_table[static_cast<size_t>(next_instruction.type())]; \
[[clang::musttail]] return (this->*fn)(bytecode, program_counter); \
} while (0)
template<typename OP>
ALWAYS_INLINE FLATTEN void Interpreter::handle_with_exception_check(u8 const* bytecode, size_t& program_counter)
{
{
auto const& instruction = *reinterpret_cast<OP const*>(&bytecode[program_counter]);
auto result = instruction.execute_impl(*this);
if (result.is_error()) [[unlikely]] {
if (handle_exception(program_counter, result.error_value()) == HandleExceptionResponse::ExitFromExecutable)
return;
DISPATCH_NEXT();
}
increment_program_counter(program_counter, instruction);
}
DISPATCH_NEXT();
}
#define HANDLE_INSTRUCTION(name) \
FLATTEN void Interpreter::handle_##name(u8 const* bytecode, size_t& program_counter) \
{ \
return handle_with_exception_check<Op::name>(bytecode, program_counter); \
}
HANDLE_INSTRUCTION(OP1);
HANDLE_INSTRUCTION(OP2);
...
```
as a rough implementation
removing the `FLATTEN` seems to make it work, so my guess is that it inlines some functions requiring some more cleanup, which somehow inhibits the tail-call, not sure what happens with the diagnostic though
I was not yet able to craft a small reproducer
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs