about summary refs log tree commit diff
path: root/src/test/codegen
diff options
context:
space:
mode:
authorScott McMurray <scottmcm@users.noreply.github.com>2022-12-22 13:44:51 -0800
committerScott McMurray <scottmcm@users.noreply.github.com>2022-12-23 15:14:54 -0800
commit4cb7bd36d7809d656d585656b9002b12d6d40e4f (patch)
tree8af5d755e2588d4a9e528efb458950d42846bee9 /src/test/codegen
parente5e4eef02d443eae5089a330e59a69a4f350db81 (diff)
downloadrust-4cb7bd36d7809d656d585656b9002b12d6d40e4f.tar.gz
rust-4cb7bd36d7809d656d585656b9002b12d6d40e4f.zip
Codegen test for derived `<` on trivial newtype [TEST ONLY]
Diffstat (limited to 'src/test/codegen')
-rw-r--r--src/test/codegen/comparison-operators-newtype.rs49
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
+}