This is an archive of the discontinued LLVM Phabricator instance.

[WebAssembly] Fix call_indirect on funcrefs
ClosedPublic

Authored by pmatos on Oct 5 2021, 7:04 AM.

Details

Summary

The currently implementation of funcrefs is broken since it is putting
the funcref itself on the stack before the call_indirect. Instead what
should be on the stack is the constant 0, which is the index at which
we store the funcref in __funcref_call_table.

Diff Detail

Event Timeline

pmatos created this revision.Oct 5 2021, 7:04 AM
pmatos requested review of this revision.Oct 5 2021, 7:04 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 5 2021, 7:04 AM
tlively accepted this revision.Oct 5 2021, 11:36 AM

Ah, yes, this fix makes sense. LGTM modulo comments.

llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
571

It would be good to add a comment about why we are adding this zero operand here.

578

Could we use CallParams.addOperand here for consistency with the other branch?

This revision is now accepted and ready to land.Oct 5 2021, 11:36 AM
pmatos added inline comments.Oct 6 2021, 1:06 AM
llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
571

Sure.

578

I don't think so. You cannot create MachineOperands from scratch. The only reason we can use the addOperand before is because we did not build the operand FnPtr, we extracted it. MachineOperands are built as part of the MachineInstrBuilder, which is what I used.

This revision was automatically updated to reflect the committed changes.