This is an archive of the discontinued LLVM Phabricator instance.

[WebAssembly] Support 'unreachable' expression
ClosedPublic

Authored by dschuff on Nov 9 2015, 2:17 PM.

Details

Summary

Lower LLVM's 'unreachable' terminator to ISD::TRAP, and lower ISD::TRAP to
wasm's 'unreachable' expression.

WebAssembly type-checks expressions, but a noreturn function with a
return type that doesn't match the context will cause a check
failure. So we lower LLVM 'unreachable' to ISD::TRAP and then lower that
to WebAssembly's 'unreachable' expression, which typechecks in any
context and causes a trap if executed.

Diff Detail

Repository
rL LLVM

Event Timeline

dschuff updated this revision to Diff 39753.Nov 9 2015, 2:17 PM
dschuff retitled this revision from to [WebAssembly] Support 'unreachable' expression.
dschuff updated this object.
dschuff added a reviewer: sunfish.
dschuff added subscribers: llvm-commits, jfb.
sunfish added inline comments.Nov 9 2015, 4:13 PM
lib/Target/WebAssembly/WebAssemblyInstrControl.td
63 ↗(On Diff #39753)

Trap-like instructions are not considered "Return" instructions in the LLVM CodeGen sense, so we should rearrange the settings here so that UNREACHABLE is outside the isReturn = 1 block.

dschuff updated this revision to Diff 39766.Nov 9 2015, 4:17 PM
  • Make UNREACHABLE not isReturn
sunfish accepted this revision.Nov 9 2015, 4:23 PM
sunfish edited edge metadata.

lgtm, thanks!

This revision is now accepted and ready to land.Nov 9 2015, 4:23 PM
This revision was automatically updated to reflect the committed changes.