-
Notifications
You must be signed in to change notification settings - Fork 12.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[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 llvm-svn: 252566
- Loading branch information
Showing
4 changed files
with
49 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
; RUN: llc < %s -asm-verbose=false | FileCheck %s | ||
; RUN: llc < %s -asm-verbose=false -fast-isel | FileCheck %s | ||
|
||
; Test that LLVM unreachable instruction and trap intrinsic are lowered to | ||
; wasm unreachable | ||
|
||
target datalayout = "e-p:32:32-i64:64-n32:64-S128" | ||
target triple = "wasm32-unknown-unknown" | ||
|
||
declare void @llvm.trap() | ||
declare void @llvm.debugtrap() | ||
declare void @abort() | ||
|
||
; CHECK-LABEL: f1: | ||
; CHECK: call $abort | ||
; CHECK: unreachable | ||
define i32 @f1() { | ||
call void @abort() | ||
unreachable | ||
} | ||
|
||
; CHECK-LABEL: f2: | ||
; CHECK: unreachable | ||
define void @f2() { | ||
call void @llvm.trap() | ||
ret void | ||
} | ||
|
||
; CHECK-LABEL: f3: | ||
; CHECK: unreachable | ||
define void @f3() { | ||
call void @llvm.debugtrap() | ||
ret void | ||
} |