Skip to content

Commit b1194d9

Browse files
committed
Add failing tests for some Option optimizations
1 parent bebcb9d commit b1194d9

File tree

3 files changed

+37
-10
lines changed

3 files changed

+37
-10
lines changed

tests/codegen/option-niche-eq.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,3 @@ pub fn niche_eq(l: Option<EnumWithNiche>, r: Option<EnumWithNiche>) -> bool {
7373
// CHECK-NEXT: ret i1
7474
l == r
7575
}
76-
77-
// FIXME: This should work too
78-
// // FIXME-CHECK-LABEL: @bool_eq
79-
// #[no_mangle]
80-
// pub fn bool_eq(l: Option<bool>, r: Option<bool>) -> bool {
81-
// // FIXME-CHECK: start:
82-
// // FIXME-CHECK-NEXT: icmp eq i8
83-
// // FIXME-CHECK-NEXT: ret i1
84-
// l == r
85-
// }
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//@ should-fail
2+
//@ compile-flags: -Copt-level=3 -Zmerge-functions=disabled
3+
//! Test for #49892 (LLVM not fully optimizing comparisons of `Option<bool>`).
4+
//! If this starts passing, it can be moved to `tests/codegen/option-niche-eq.rs`
5+
#![crate_type = "lib"]
6+
7+
// CHECK-LABEL: @bool_eq
8+
#[no_mangle]
9+
pub fn bool_eq(l: Option<bool>, r: Option<bool>) -> bool {
10+
// CHECK: start:
11+
// CHECK-NEXT: icmp eq i8
12+
// CHECK-NEXT: ret i1
13+
l == r
14+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//@ should-fail
2+
//@ compile-flags: -Copt-level=3 -Zmerge-functions=disabled
3+
//! Test that the derived implementation of `PartialEq` for `Option` is not fully
4+
//! optimized by LLVM. If this starts passing, the test and manual impl should
5+
//! be removed.
6+
#![crate_type = "lib"]
7+
8+
use std::num::NonZero;
9+
10+
#[derive(Copy, Clone, PartialEq, Eq)]
11+
pub enum Option<T> {
12+
None,
13+
Some(T),
14+
}
15+
16+
// CHECK-LABEL: @non_zero_eq
17+
#[no_mangle]
18+
pub fn non_zero_eq(l: Option<NonZero<u32>>, r: Option<NonZero<u32>>) -> bool {
19+
// CHECK: start:
20+
// CHECK-NEXT: icmp eq i32
21+
// CHECK-NEXT: ret i1
22+
l == r
23+
}

0 commit comments

Comments
 (0)