[WebAssembly] Support 'unreachable' expression
authorDerek Schuff <dschuff@google.com>
Tue, 10 Nov 2015 00:30:57 +0000 (00:30 +0000)
committerDerek Schuff <dschuff@google.com>
Tue, 10 Nov 2015 00:30:57 +0000 (00:30 +0000)
commit537330de8268f3592b5f98987da5f74a808d2670
tree65e975b3529e0e45ae90f07a3d29f5e88f769aff
parent76916424bef4b5043d90e2f2dd15fb3dda9c029e
[WebAssembly] Support 'unreachable' expression

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.

Differential Revision: http://reviews.llvm.org/D14515

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@252566 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
lib/Target/WebAssembly/WebAssemblyInstrControl.td
lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
test/CodeGen/WebAssembly/unreachable.ll [new file with mode: 0644]