about summary refs log tree commit diff
path: root/tests/codegen/enum
diff options
context:
space:
mode:
authorDianQK <dianqk@dianqk.net>2024-02-14 12:02:22 +0800
committerDianQK <dianqk@dianqk.net>2024-03-07 22:58:51 +0800
commit08ae8380ce75b4a19c4a7bfa33eac8776daef532 (patch)
treed99aa37997c1e213eccb92f77144bc49130241f5 /tests/codegen/enum
parentd8b7b5be7d4738dae63fbc35ed4b44ef97cf7ca2 (diff)
downloadrust-08ae8380ce75b4a19c4a7bfa33eac8776daef532.tar.gz
rust-08ae8380ce75b4a19c4a7bfa33eac8776daef532.zip
Replace the default branch with an unreachable branch If it is the last variant
Diffstat (limited to 'tests/codegen/enum')
-rw-r--r--tests/codegen/enum/uninhabited_enum_default_branch.rs24
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/codegen/enum/uninhabited_enum_default_branch.rs b/tests/codegen/enum/uninhabited_enum_default_branch.rs
new file mode 100644
index 00000000000..5f318f18dec
--- /dev/null
+++ b/tests/codegen/enum/uninhabited_enum_default_branch.rs
@@ -0,0 +1,24 @@
+//@ compile-flags: -O
+
+#![crate_type = "lib"]
+
+#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
+pub struct Int(u32);
+
+const A: Int = Int(201);
+const B: Int = Int(270);
+const C: Int = Int(153);
+
+// CHECK-LABEL: @foo(
+// CHECK-SAME: [[TMP0:%.*]])
+// CHECK-NEXT:  start:
+// CHECK-NEXT:    [[TMP1:%.*]] = add i32 [[TMP0]], -201
+// CHECK-NEXT:    icmp ult i32 [[TMP1]], 70
+// CHECK-NEXT:    icmp eq i32 [[TMP0]], 153
+// CHECK-NEXT:    [[SPEC_SELECT:%.*]] = or i1
+// CHECK-NEXT:    ret i1 [[SPEC_SELECT]]
+#[no_mangle]
+pub fn foo(x: Int) -> bool {
+    (x >= A && x <= B)
+        || x == C
+}