diff options
| author | bors <bors@rust-lang.org> | 2022-12-24 10:46:43 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-12-24 10:46:43 +0000 |
| commit | 8766bbdc30a297aaa249193f5513fb261ccef17c (patch) | |
| tree | 4b6141e66c79bd3545e280cabe09e22cd3342dcb /src/test/codegen | |
| parent | 5e8bab91d339037388d152fd5066c26ae707d54e (diff) | |
| parent | 750bf73aea78a613456dc93f34cc32e43e9252f8 (diff) | |
| download | rust-8766bbdc30a297aaa249193f5513fb261ccef17c.tar.gz rust-8766bbdc30a297aaa249193f5513fb261ccef17c.zip | |
Auto merge of #106111 - matthiaskrgr:rollup-nnpoe5h, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - #105465 (Improve top-level docs) - #105872 (Suggest remove last method call when type coerce with expected type) - #106032 (std: only use LFS function on glibc) - #106078 (Provide more context on FileCheck failures) - #106100 (Codegen test for derived `<` on trivial newtype [TEST ONLY]) - #106109 (rustdoc: make line number CSS for doc comment and scraped the same) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'src/test/codegen')
| -rw-r--r-- | src/test/codegen/comparison-operators-newtype.rs | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/test/codegen/comparison-operators-newtype.rs b/src/test/codegen/comparison-operators-newtype.rs new file mode 100644 index 00000000000..5cf6c3ac0a2 --- /dev/null +++ b/src/test/codegen/comparison-operators-newtype.rs @@ -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 +} |
