-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Duplicated WASM unreachable
instructions
#102132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@rustbot label +A-codegen +O-wasm |
This isn't just a WASM thing but a general codegen thing where LLVM still inserts the |
@rustbot label -O-wasm +A-llvm |
I'm having a look into this. The x86 and Wasm examples may not be entirely related, as llc targeting x86 doesn't exhibit this bug: https://godbolt.org/z/qcqhYbqz5 Even going back to older llc versions in Godbolt doesn't reproduce the bug, so I assume for the x86 case it's either a bug in rustc's llvm fork, or an issue with the way rustc is using llvm. |
I've identified a suspicious unstable rustc option Another function of interest is Among the various parties (rustc, llvm, wasm), there are different understandings of what "unreachable" means. I wonder if this is contributing to the problems. |
I also found this related llvm issue: https://reviews.llvm.org/D66980 |
It turns out LLVM has a NoTrapAfterNoreturn to complement the TrapUnreachable option. Making rustc use that option fixes the x86 case. I found this issue: #88826 about turning TrapUnreachable off by default. @nikic do you think it's safe to turn TrapUnreachable off yet? If not, would a pull request enabling NoTrapAfterNoReturn be welcome? I still have yet to investigate the Wasm case more thoroughly. |
@majaha I'd suggest filing an MCP (https://forge.rust-lang.org/compiler/mcp.html) for enabling NoTrapAfterNoReturn. I think doing this is fine, but other people may have concerns. |
Targets:
wasm32-unknown-unknown
,wasm32-wasi
When calling
core::arch::wasm32::unreachable()
, the generated WASM contains twounreachable
instructions instead of only one.Example:
Output (from Godbolt):
Godbolt link: https://rust.godbolt.org/z/Yqz6Kh9eq
This is mostly noticeable when using
build-std-features=panic_immediate_abort
(which I know is unstable), as all instances ofpanic!()
are basically replaced withunreachable()
, and then compile down to twounreachable
instructions.This behavior appears to have been present since
core::arch::wasm32::unreachable()
was made available, so this is not a regression.The text was updated successfully, but these errors were encountered: