]> git.proxmox.com Git - rustc.git/blobdiff - src/test/codegen/issue-77812.rs
Merge tag 'debian/1.52.1+dfsg1-1_exp2' into proxmox/buster
[rustc.git] / src / test / codegen / issue-77812.rs
diff --git a/src/test/codegen/issue-77812.rs b/src/test/codegen/issue-77812.rs
new file mode 100644 (file)
index 0000000..9504257
--- /dev/null
@@ -0,0 +1,33 @@
+// min-llvm-version: 12.0.0
+// compile-flags: -O
+#![crate_type = "lib"]
+
+// Test that LLVM can eliminate the unreachable `Variant::Zero` branch.
+
+#[derive(Copy, Clone, Eq, PartialEq)]
+pub enum Variant {
+    Zero,
+    One,
+    Two,
+}
+
+extern {
+    fn exf1();
+    fn exf2();
+}
+
+pub static mut GLOBAL: Variant = Variant::Zero;
+
+// CHECK-LABEL: @issue_77812
+#[no_mangle]
+pub unsafe fn issue_77812() {
+    let g = GLOBAL;
+    if g != Variant::Zero {
+        match g {
+            Variant::One => exf1(),
+            Variant::Two => exf2(),
+            // CHECK-NOT: panic
+            Variant::Zero => panic!(),
+        }
+    }
+}