-
-
Notifications
You must be signed in to change notification settings - Fork 14.3k
Added codegen tests for different forms of Option::or
#150564
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
+174
−0
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
80acf74
test: added codegen tests for permutations of `Option::or`
rwardd bf2078b
fix: add `CHECK-SAME` labels to verify generated function type for `u…
rwardd 66c4ead
fix: added further `CHECK-SAME` labels and replaced all `struct` inpu…
rwardd 3df06f5
fix: use `std::num::NonZero` instead of `extern crate` and extend inf…
rwardd a2fcb0d
fix: add `CHECK` directives to `ret` comments and be more pervasive w…
rwardd 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
155 changes: 155 additions & 0 deletions
155
tests/codegen-llvm/issues/multiple-option-or-permutations.rs
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 |
|---|---|---|
| @@ -0,0 +1,155 @@ | ||
| // Tests output of multiple permutations of `Option::or` | ||
| //@ compile-flags: -Copt-level=3 -Zmerge-functions=disabled | ||
|
|
||
| #![crate_type = "lib"] | ||
|
|
||
| // CHECK-LABEL: @or_match_u8 | ||
| #[no_mangle] | ||
| pub fn or_match_u8(opta: Option<u8>, optb: Option<u8>) -> Option<u8> { | ||
| // CHECK: start: | ||
| // CHECK-NEXT: or i1 %0 | ||
| // CHECK-NEXT: select i1 %0 | ||
rwardd marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // CHECK-NEXT: insertvalue { i1, i8 } | ||
| // CHECK-NEXT: insertvalue { i1, i8 } | ||
| // ret { i1, i8 } | ||
| match opta { | ||
| Some(x) => Some(x), | ||
| None => optb, | ||
| } | ||
| } | ||
|
|
||
| // CHECK-LABEL: @or_match_alt_u8 | ||
rwardd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| #[no_mangle] | ||
| pub fn or_match_alt_u8(opta: Option<u8>, optb: Option<u8>) -> Option<u8> { | ||
| // CHECK: start: | ||
| // CHECK-NEXT: select i1 | ||
| // CHECK-NEXT: or i1 | ||
rwardd marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // CHECK-NEXT: insertvalue { i1, i8 } | ||
| // CHECK-NEXT: insertvalue { i1, i8 } | ||
| // ret { i1, i8 } | ||
| match opta { | ||
| Some(_) => opta, | ||
| None => optb, | ||
| } | ||
| } | ||
|
|
||
| // CHECK-LABEL: @option_or_u8 | ||
| #[no_mangle] | ||
| pub fn option_or_u8(opta: Option<u8>, optb: Option<u8>) -> Option<u8> { | ||
| // CHECK: start: | ||
| // CHECK-NEXT: select i1 | ||
| // CHECK-NEXT: or i1 | ||
| // CHECK-NEXT: insertvalue { i1, i8 } | ||
| // CHECK-NEXT: insertvalue { i1, i8 } | ||
| // ret { i1, i8 } | ||
| opta.or(optb) | ||
| } | ||
|
|
||
| // CHECK-LABEL: @if_some_u8 | ||
| #[no_mangle] | ||
| pub fn if_some_u8(opta: Option<u8>, optb: Option<u8>) -> Option<u8> { | ||
| // CHECK: start: | ||
| // CHECK-NEXT: select i1 | ||
| // CHECK-NEXT: or i1 | ||
| // CHECK-NEXT: insertvalue { i1, i8 } | ||
| // CHECK-NEXT: insertvalue { i1, i8 } | ||
| // ret { i1, i8 } | ||
| if opta.is_some() { opta } else { optb } | ||
| } | ||
|
|
||
| // CHECK-LABEL: @or_match_slice_u8 | ||
rwardd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| #[no_mangle] | ||
| pub fn or_match_slice_u8(opta: Option<[u8; 1]>, optb: Option<[u8; 1]>) -> Option<[u8; 1]> { | ||
| // CHECK: start: | ||
| // CHECK-NEXT: trunc i16 %0 to i1 | ||
| // CHECK-NEXT: select i1 %2, i16 %0, i16 %1 | ||
| // ret i16 | ||
| match opta { | ||
| Some(x) => Some(x), | ||
| None => optb, | ||
| } | ||
| } | ||
|
|
||
| // CHECK-LABEL: @or_match_slice_alt_u8 | ||
| #[no_mangle] | ||
| pub fn or_match_slice_alt_u8(opta: Option<[u8; 1]>, optb: Option<[u8; 1]>) -> Option<[u8; 1]> { | ||
| // CHECK: start: | ||
| // CHECK-NEXT: trunc i16 %0 to i1 | ||
| // CHECK-NEXT: select i1 %2, i16 %0, i16 %1 | ||
| // ret i16 | ||
| match opta { | ||
| Some(_) => opta, | ||
| None => optb, | ||
| } | ||
| } | ||
|
|
||
| // CHECK-LABEL: @option_or_slice_u8 | ||
| #[no_mangle] | ||
| pub fn option_or_slice_u8(opta: Option<[u8; 1]>, optb: Option<[u8; 1]>) -> Option<[u8; 1]> { | ||
| // CHECK: start: | ||
| // CHECK-NEXT: trunc i16 %0 to i1 | ||
| // CHECK-NEXT: select i1 %2, i16 %0, i16 %1 | ||
| // ret i16 | ||
| opta.or(optb) | ||
| } | ||
|
|
||
| // CHECK-LABEL: @if_some_slice_u8 | ||
| #[no_mangle] | ||
| pub fn if_some_slice_u8(opta: Option<[u8; 1]>, optb: Option<[u8; 1]>) -> Option<[u8; 1]> { | ||
| // CHECK: start: | ||
| // CHECK-NEXT: trunc i16 %0 to i1 | ||
| // CHECK-NEXT: select i1 %2, i16 %0, i16 %1 | ||
| // ret i16 | ||
| if opta.is_some() { opta } else { optb } | ||
| } | ||
|
|
||
| pub struct Test { | ||
| _a: u8, | ||
| _b: u8, | ||
| } | ||
rwardd marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| // CHECK-LABEL: @or_match_type | ||
| #[no_mangle] | ||
| pub fn or_match_type(opta: Option<Test>, optb: Option<Test>) -> Option<Test> { | ||
| // CHECK: start: | ||
| // CHECK-NEXT: trunc i24 %0 to i1 | ||
| // CHECK-NEXT: select i1 %2, i24 %0, i24 %1 | ||
| // ret i24 | ||
| match opta { | ||
| Some(x) => Some(x), | ||
| None => optb, | ||
| } | ||
| } | ||
|
|
||
| // CHECK-LABEL: @or_match_alt_type | ||
| #[no_mangle] | ||
| pub fn or_match_alt_type(opta: Option<Test>, optb: Option<Test>) -> Option<Test> { | ||
| // CHECK: start: | ||
| // CHECK-NEXT: trunc i24 %0 to i1 | ||
| // CHECK-NEXT: select i1 %2, i24 %0, i24 %1 | ||
| // ret i24 | ||
| match opta { | ||
| Some(_) => opta, | ||
| None => optb, | ||
| } | ||
| } | ||
|
|
||
| // CHECK-LABEL: @option_or_type | ||
| #[no_mangle] | ||
| pub fn option_or_type(opta: Option<Test>, optb: Option<Test>) -> Option<Test> { | ||
| // CHECK: start: | ||
| // CHECK-NEXT: trunc i24 %0 to i1 | ||
| // CHECK-NEXT: select i1 %2, i24 %0, i24 %1 | ||
| // ret i24 | ||
| opta.or(optb) | ||
| } | ||
|
|
||
| // CHECK-LABEL: @if_some_type | ||
| #[no_mangle] | ||
| pub fn if_some_type(opta: Option<Test>, optb: Option<Test>) -> Option<Test> { | ||
| // CHECK: start: | ||
| // CHECK-NEXT: trunc i24 %0 to i1 | ||
| // CHECK-NEXT: select i1 %2, i24 %0, i24 %1 | ||
| // ret i24 | ||
| if opta.is_some() { opta } else { optb } | ||
| } | ||
Oops, something went wrong.
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.