Skip to content

Commit

Permalink
Rollup merge of rust-lang#131920 - clubby789:108395-test, r=jieyouxu
Browse files Browse the repository at this point in the history
Add codegen test for branchy bool match

Closes rust-lang#108395
  • Loading branch information
matthiaskrgr authored Oct 19, 2024
2 parents a67227e + aa299a9 commit 1aa97ac
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions tests/codegen/issues/issue-108395-branchy-bool-match.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//@ compile-flags: -O -Zmerge-functions=disabled
//! Test for <https://github.com/rust-lang/rust/issues/108395>. Check that
//! matching on two bools with wildcards does not produce branches.
#![crate_type = "lib"]

// CHECK-LABEL: @wildcard(
#[no_mangle]
pub fn wildcard(a: u16, b: u16, v: u16) -> u16 {
// CHECK-NOT: br
match (a == v, b == v) {
(true, false) => 0,
(false, true) => u16::MAX,
_ => 1 << 15, // half
}
}

// CHECK-LABEL: @exhaustive(
#[no_mangle]
pub fn exhaustive(a: u16, b: u16, v: u16) -> u16 {
// CHECK-NOT: br
match (a == v, b == v) {
(true, false) => 0,
(false, true) => u16::MAX,
(true, true) => 1 << 15,
(false, false) => 1 << 15,
}
}

0 comments on commit 1aa97ac

Please sign in to comment.