Skip to content

Commit

Permalink
refine common_prim test
Browse files Browse the repository at this point in the history
Co-authored-by: Scott McMurray <scottmcm@users.noreply.github.com>
  • Loading branch information
erikdesjardins and scottmcm committed Mar 13, 2024
1 parent 5ccada6 commit 9f55200
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions tests/codegen/common_prim_int_ptr.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//@ compile-flags: -O

#![crate_type = "lib"]
#![feature(core_intrinsics)]

// Tests that codegen works properly when enums like `Result<usize, Box<()>>`
// are represented as `{ u64, ptr }`, i.e., for `Ok(123)`, `123` is stored
Expand All @@ -26,18 +27,25 @@ pub fn insert_box(x: Box<()>) -> Result<usize, Box<()>> {
}

// 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, Box<()>>) -> 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<usize, Box<()>>) -> Box<()> {
// CHECK-NOT: ptrtoint
// CHECK-NOT: inttoptr
// CHECK-NOT: load
// CHECK-NOT: store
x.unwrap_err_unchecked()
pub unsafe fn extract_box(x: Result<usize, Box<i32>>) -> Box<i32> {
// CHECK: ret ptr [[PAYLOAD]]
match x {
Ok(_) => std::intrinsics::unreachable(),
Err(e) => e,
}
}

0 comments on commit 9f55200

Please sign in to comment.