From 08ae8380ce75b4a19c4a7bfa33eac8776daef532 Mon Sep 17 00:00:00 2001 From: DianQK Date: Wed, 14 Feb 2024 12:02:22 +0800 Subject: Replace the default branch with an unreachable branch If it is the last variant --- .../enum/uninhabited_enum_default_branch.rs | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 tests/codegen/enum/uninhabited_enum_default_branch.rs (limited to 'tests/codegen/enum') 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 +} -- cgit 1.4.1-3-g733a5