From 9f55200a42f599549fee0f003b27888d03604861 Mon Sep 17 00:00:00 2001 From: Erik Desjardins Date: Wed, 13 Mar 2024 01:17:15 -0400 Subject: [PATCH] refine common_prim test Co-authored-by: Scott McMurray --- tests/codegen/common_prim_int_ptr.rs | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/tests/codegen/common_prim_int_ptr.rs b/tests/codegen/common_prim_int_ptr.rs index 666ccc5a2cff3..87fa89abb8667 100644 --- a/tests/codegen/common_prim_int_ptr.rs +++ b/tests/codegen/common_prim_int_ptr.rs @@ -1,6 +1,7 @@ //@ compile-flags: -O #![crate_type = "lib"] +#![feature(core_intrinsics)] // Tests that codegen works properly when enums like `Result>` // are represented as `{ u64, ptr }`, i.e., for `Ok(123)`, `123` is stored @@ -26,18 +27,25 @@ pub fn insert_box(x: Box<()>) -> Result> { } // CHECK-LABEL: @extract_int +// CHECK-NOT: nonnull +// CHECK-SAME: (i{{[0-9]+}} {{[^,]+}} [[DISCRIMINANT:%[0-9]+]], ptr {{[^,]+}} [[PAYLOAD:%[0-9]+]]) #[no_mangle] pub unsafe fn extract_int(x: Result>) -> usize { - // CHECK: ptrtoint - x.unwrap_unchecked() + // CHECK: [[TEMP:%.+]] = ptrtoint ptr [[PAYLOAD]] to [[USIZE:i[0-9]+]] + // CHECK: ret [[USIZE]] [[TEMP]] + match x { + Ok(v) => v, + Err(_) => std::intrinsics::unreachable(), + } } // CHECK-LABEL: @extract_box +// CHECK-SAME: (i{{[0-9]+}} {{[^,]+}} [[DISCRIMINANT:%[0-9]+]], ptr {{[^,]+}} [[PAYLOAD:%[0-9]+]]) #[no_mangle] -pub unsafe fn extract_box(x: Result>) -> Box<()> { - // CHECK-NOT: ptrtoint - // CHECK-NOT: inttoptr - // CHECK-NOT: load - // CHECK-NOT: store - x.unwrap_err_unchecked() +pub unsafe fn extract_box(x: Result>) -> Box { + // CHECK: ret ptr [[PAYLOAD]] + match x { + Ok(_) => std::intrinsics::unreachable(), + Err(e) => e, + } }