This is an archive of the discontinued LLVM Phabricator instance.

[WebAssembly] Fix tail call with return_call_indirect instruction
AcceptedPublic

Authored by yamt on Jan 26 2023, 4:27 AM.

Details

Reviewers
aheejin
dschuff
Summary

A musttail with function pointers doesn't rewind C stack without this.

Diff Detail

Event Timeline

yamt created this revision.Jan 26 2023, 4:27 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 26 2023, 4:27 AM
yamt requested review of this revision.Jan 26 2023, 4:27 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 26 2023, 4:27 AM
asb added a comment.Jan 30 2023, 7:38 AM

Are you able to provide a test case that demonstrates the codegen change?

yamt added a comment.Jan 30 2023, 8:06 AM

Are you able to provide a test case that demonstrates the codegen change?

this function is broken without this change: https://github.com/yamt/garbage/blob/51ec5aaea4e30c9eece7665dea78cb71364076e2/wasm/tail-call/b.c#L12

do you mean adding a test case in llvm tree? i'm not familiar with it. if you mean so, can you point me where to add?

yamt added a comment.Jan 30 2023, 8:50 AM

Are you able to provide a test case that demonstrates the codegen change?

this function is broken without this change: https://github.com/yamt/garbage/blob/51ec5aaea4e30c9eece7665dea78cb71364076e2/wasm/tail-call/b.c#L12

sorry, i linked to a wrong function.
actually this function: https://github.com/yamt/garbage/blob/51ec5aaea4e30c9eece7665dea78cb71364076e2/wasm/tail-call/a.c#L7

yamt updated this revision to Diff 493486.Jan 30 2023, 10:41 PM

i added a test.

yamt updated this revision to Diff 493487.Jan 30 2023, 10:44 PM

remove an unnecessary line in the test

aheejin accepted this revision.Feb 27 2023, 1:45 PM

LGTM % comment

llvm/test/CodeGen/WebAssembly/tailcall.ll
260

Can you add a little more comment that says this test is to test if SP restoring code is generated correctly before the return_call?

This revision is now accepted and ready to land.Feb 27 2023, 1:45 PM

FYI, not sure why this hasn't landed so far, but D146569 is fixing the same issue.

yamt updated this revision to Diff 507185.Mar 21 2023, 5:11 PM

add comment

yamt marked an inline comment as done.Mar 21 2023, 5:12 PM
yamt added inline comments.
llvm/test/CodeGen/WebAssembly/tailcall.ll
260

done

Thanks for fixing this, but D146569 has landed first.