mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-01 06:51:58 +00:00
Rollup merge of #106100 - scottmcm:derived-less-than-test, r=compiler-errors
Codegen test for derived `<` on trivial newtype [TEST ONLY] I originally wrote this for #106065, but the libcore changes there aren't necessarily a win. So I pulled out this test to be its own PR since it's important (see https://github.com/rust-lang/rust/pull/105840#discussion_r1056030324) and well-intentioned changes to core or the derive could accidentally break it without that being obvious (other than by massive unexplained perf changes).
This commit is contained in:
commit
09ee7048fd
49
src/test/codegen/comparison-operators-newtype.rs
Normal file
49
src/test/codegen/comparison-operators-newtype.rs
Normal file
@ -0,0 +1,49 @@
|
||||
// The `derive(PartialOrd)` for a newtype doesn't override `lt`/`le`/`gt`/`ge`.
|
||||
// This double-checks that the `Option<Ordering>` intermediate values used
|
||||
// in the operators for such a type all optimize away.
|
||||
|
||||
// compile-flags: -C opt-level=1
|
||||
// min-llvm-version: 15.0
|
||||
|
||||
#![crate_type = "lib"]
|
||||
|
||||
use std::cmp::Ordering;
|
||||
|
||||
#[derive(PartialOrd, PartialEq)]
|
||||
pub struct Foo(u16);
|
||||
|
||||
// CHECK-LABEL: @check_lt
|
||||
// CHECK-SAME: (i16 %[[A:.+]], i16 %[[B:.+]])
|
||||
#[no_mangle]
|
||||
pub fn check_lt(a: Foo, b: Foo) -> bool {
|
||||
// CHECK: %[[R:.+]] = icmp ult i16 %[[A]], %[[B]]
|
||||
// CHECK-NEXT: ret i1 %[[R]]
|
||||
a < b
|
||||
}
|
||||
|
||||
// CHECK-LABEL: @check_le
|
||||
// CHECK-SAME: (i16 %[[A:.+]], i16 %[[B:.+]])
|
||||
#[no_mangle]
|
||||
pub fn check_le(a: Foo, b: Foo) -> bool {
|
||||
// CHECK: %[[R:.+]] = icmp ule i16 %[[A]], %[[B]]
|
||||
// CHECK-NEXT: ret i1 %[[R]]
|
||||
a <= b
|
||||
}
|
||||
|
||||
// CHECK-LABEL: @check_gt
|
||||
// CHECK-SAME: (i16 %[[A:.+]], i16 %[[B:.+]])
|
||||
#[no_mangle]
|
||||
pub fn check_gt(a: Foo, b: Foo) -> bool {
|
||||
// CHECK: %[[R:.+]] = icmp ugt i16 %[[A]], %[[B]]
|
||||
// CHECK-NEXT: ret i1 %[[R]]
|
||||
a > b
|
||||
}
|
||||
|
||||
// CHECK-LABEL: @check_ge
|
||||
// CHECK-SAME: (i16 %[[A:.+]], i16 %[[B:.+]])
|
||||
#[no_mangle]
|
||||
pub fn check_ge(a: Foo, b: Foo) -> bool {
|
||||
// CHECK: %[[R:.+]] = icmp uge i16 %[[A]], %[[B]]
|
||||
// CHECK-NEXT: ret i1 %[[R]]
|
||||
a >= b
|
||||
}
|
Loading…
Reference in New Issue
Block a user