-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Ensure NoTrapAfterNoreturn is false for the wasm backend #65876
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
7c43c80
Add no-trap-after-noreturn flag and wasm tests
majaha 7e83469
Ensure NoTrapAfterNoreturn is false for wasm
majaha c8ad813
Add peephole optimisation
majaha 219c194
Fix broken lld wasm test
majaha 91d5986
Revert "Fix broken lld wasm test"
majaha d2b5701
Revert "Add peephole optimisation"
majaha 05d0c17
Run clang-format
majaha 35f6103
Fix test comments
majaha e1af076
Merge branch 'llvm:main' into wasmntanr
majaha 3cb13e5
Apply formatting and naming changes from code review
majaha 0393836
Improve explanation in unreachable.ll test
majaha c210e9a
Remove unintended "CHECK-NEXT" line
majaha f0b5809
Expand "unreach" -> "unreachable"
majaha b2d9080
Adresss comments
majaha 02a5d64
Apply suggestions from code review
majaha fdc6b54
Add newline
majaha File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
@@ -1,33 +1,128 @@ | ||
; RUN: llc < %s -asm-verbose=false -verify-machineinstrs | FileCheck %s | ||
; RUN: llc < %s -asm-verbose=false -fast-isel -fast-isel-abort=1 -verify-machineinstrs | FileCheck %s | ||
|
||
; Test that LLVM unreachable instruction and trap intrinsic are lowered to | ||
; wasm unreachable | ||
; RUN: llc < %s -verify-machineinstrs | FileCheck %s | ||
majaha marked this conversation as resolved.
Show resolved
Hide resolved
majaha marked this conversation as resolved.
Show resolved
Hide resolved
|
||
; RUN: llc < %s -fast-isel -fast-isel-abort=1 -verify-machineinstrs | FileCheck %s | ||
; RUN: llc < %s -verify-machineinstrs --trap-unreachable | FileCheck %s | ||
; RUN: llc < %s -fast-isel -fast-isel-abort=1 -verify-machineinstrs --trap-unreachable | FileCheck %s | ||
; RUN: llc < %s -verify-machineinstrs --trap-unreachable --no-trap-after-noreturn | FileCheck %s | ||
; RUN: llc < %s -fast-isel -fast-isel-abort=1 -verify-machineinstrs --trap-unreachable --no-trap-after-noreturn | FileCheck %s | ||
|
||
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 | ||
} | ||
; Test that the LLVM trap and debug trap intrinsics are lowered to wasm unreachable. | ||
majaha marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
declare void @llvm.trap() cold noreturn nounwind | ||
declare void @llvm.debugtrap() nounwind | ||
|
||
; CHECK-LABEL: f2: | ||
; CHECK: unreachable | ||
define void @f2() { | ||
define void @trap_ret_void() { | ||
; CHECK-LABEL: trap_ret_void: | ||
; CHECK: .functype trap_ret_void () -> () | ||
; CHECK-NEXT: # %bb.0: | ||
; CHECK-NEXT: unreachable | ||
; CHECK-NEXT: # fallthrough-return | ||
; CHECK-NEXT: end_function | ||
call void @llvm.trap() | ||
ret void | ||
} | ||
|
||
; CHECK-LABEL: f3: | ||
; CHECK: unreachable | ||
define void @f3() { | ||
define void @dtrap_ret_void() { | ||
; CHECK-LABEL: dtrap_ret_void: | ||
; CHECK: .functype dtrap_ret_void () -> () | ||
majaha marked this conversation as resolved.
Show resolved
Hide resolved
|
||
; CHECK-NEXT: # %bb.0: | ||
; CHECK-NEXT: unreachable | ||
; CHECK-NEXT: # fallthrough-return | ||
; CHECK-NEXT: end_function | ||
call void @llvm.debugtrap() | ||
ret void | ||
} | ||
|
||
; Test that LLVM trap followed by LLVM unreachable becomes exactly one wasm unreachable. | ||
majaha marked this conversation as resolved.
Show resolved
Hide resolved
|
||
define void @trap_unreach() { | ||
; CHECK-LABEL: trap_unreach: | ||
; CHECK: .functype trap_unreach () -> () | ||
majaha marked this conversation as resolved.
Show resolved
Hide resolved
|
||
; CHECK-NEXT: # %bb.0: | ||
; CHECK-NEXT: unreachable | ||
; CHECK-NEXT: end_function | ||
call void @llvm.trap() | ||
unreachable | ||
} | ||
|
||
|
||
; Test that LLVM unreachable instruction is lowered to wasm unreachable when necessary | ||
; to fulfill the wasm operand stack requirements. | ||
|
||
declare void @ext_func() | ||
declare i32 @ext_func_i32() | ||
declare void @ext_never_return() noreturn | ||
|
||
; This test emits wasm unreachable to fill in for the missing i32 return value. | ||
majaha marked this conversation as resolved.
Show resolved
Hide resolved
|
||
define i32 @missing_ret_unreach() { | ||
; CHECK-LABEL: missing_ret_unreach: | ||
; CHECK: .functype missing_ret_unreach () -> (i32) | ||
majaha marked this conversation as resolved.
Show resolved
Hide resolved
|
||
; CHECK-NEXT: # %bb.0: | ||
; CHECK-NEXT: call ext_func | ||
; CHECK-NEXT: unreachable | ||
; CHECK-NEXT: end_function | ||
call void @ext_func() | ||
unreachable | ||
} | ||
|
||
; This is similar to the above test, but ensures wasm unreachable is emitted even | ||
; after a noreturn call. | ||
define i32 @missing_ret_noreturn_unreach() { | ||
; CHECK-LABEL: missing_ret_noreturn_unreach: | ||
; CHECK: .functype missing_ret_noreturn_unreach () -> (i32) | ||
majaha marked this conversation as resolved.
Show resolved
Hide resolved
|
||
; CHECK-NEXT: # %bb.0: | ||
; CHECK-NEXT: call ext_never_return | ||
; CHECK-NEXT: unreachable | ||
; CHECK-NEXT: end_function | ||
call void @ext_never_return() | ||
unreachable | ||
} | ||
|
||
; We could emit no instructions at all for the llvm unreachables in these next three tests, as the signatures match | ||
; and reaching llvm unreachable is undefined behaviour. But wasm unreachable is emitted for the time being. | ||
|
||
define void @void_sig_match_unreach() { | ||
; CHECK-LABEL: void_sig_match_unreach: | ||
; CHECK: .functype void_sig_match_unreach () -> () | ||
majaha marked this conversation as resolved.
Show resolved
Hide resolved
|
||
; CHECK-NEXT: # %bb.0: | ||
; CHECK-NEXT: call ext_func | ||
; CHECK-NEXT: unreachable | ||
; CHECK-NEXT: end_function | ||
call void @ext_func() | ||
unreachable | ||
} | ||
|
||
define i32 @i32_sig_match_unreach() { | ||
; CHECK-LABEL: i32_sig_match_unreach: | ||
; CHECK: .functype i32_sig_match_unreach () -> (i32) | ||
majaha marked this conversation as resolved.
Show resolved
Hide resolved
|
||
; CHECK-NEXT: # %bb.0: | ||
; CHECK-NEXT: call ext_func_i32 | ||
; CHECK-NEXT: unreachable | ||
; CHECK-NEXT: end_function | ||
call i32 @ext_func_i32() | ||
unreachable | ||
} | ||
|
||
define void @void_sig_match_noreturn_unreach() { | ||
; CHECK-LABEL: void_sig_match_noreturn_unreach: | ||
; CHECK: .functype void_sig_match_noreturn_unreach () -> () | ||
majaha marked this conversation as resolved.
Show resolved
Hide resolved
|
||
; CHECK-NEXT: # %bb.0: | ||
; CHECK-NEXT: call ext_never_return | ||
; CHECK-NEXT: unreachable | ||
; CHECK-NEXT: end_function | ||
call void @ext_never_return() | ||
unreachable | ||
} | ||
|
||
; This function currently doesn't emit unreachable. | ||
majaha marked this conversation as resolved.
Show resolved
Hide resolved
|
||
define void @void_sig_match_noreturn_ret() { | ||
; CHECK-LABEL: void_sig_match_noreturn_ret: | ||
; CHECK: .functype void_sig_match_noreturn_ret () -> () | ||
; CHECK-NEXT: # %bb.0: | ||
; CHECK-NEXT: call ext_never_return | ||
; CHECK-NEXT: # fallthrough-return | ||
; CHECK-NEXT: end_function | ||
call void @ext_never_return() | ||
ret void | ||
} |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.