Skip to content

Commit 9f55200

Browse files
refine common_prim test
Co-authored-by: Scott McMurray <[email protected]>
1 parent 5ccada6 commit 9f55200

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

tests/codegen/common_prim_int_ptr.rs

+16-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//@ compile-flags: -O
22

33
#![crate_type = "lib"]
4+
#![feature(core_intrinsics)]
45

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

2829
// CHECK-LABEL: @extract_int
30+
// CHECK-NOT: nonnull
31+
// CHECK-SAME: (i{{[0-9]+}} {{[^,]+}} [[DISCRIMINANT:%[0-9]+]], ptr {{[^,]+}} [[PAYLOAD:%[0-9]+]])
2932
#[no_mangle]
3033
pub unsafe fn extract_int(x: Result<usize, Box<()>>) -> usize {
31-
// CHECK: ptrtoint
32-
x.unwrap_unchecked()
34+
// CHECK: [[TEMP:%.+]] = ptrtoint ptr [[PAYLOAD]] to [[USIZE:i[0-9]+]]
35+
// CHECK: ret [[USIZE]] [[TEMP]]
36+
match x {
37+
Ok(v) => v,
38+
Err(_) => std::intrinsics::unreachable(),
39+
}
3340
}
3441

3542
// CHECK-LABEL: @extract_box
43+
// CHECK-SAME: (i{{[0-9]+}} {{[^,]+}} [[DISCRIMINANT:%[0-9]+]], ptr {{[^,]+}} [[PAYLOAD:%[0-9]+]])
3644
#[no_mangle]
37-
pub unsafe fn extract_box(x: Result<usize, Box<()>>) -> Box<()> {
38-
// CHECK-NOT: ptrtoint
39-
// CHECK-NOT: inttoptr
40-
// CHECK-NOT: load
41-
// CHECK-NOT: store
42-
x.unwrap_err_unchecked()
45+
pub unsafe fn extract_box(x: Result<usize, Box<i32>>) -> Box<i32> {
46+
// CHECK: ret ptr [[PAYLOAD]]
47+
match x {
48+
Ok(_) => std::intrinsics::unreachable(),
49+
Err(e) => e,
50+
}
4351
}

0 commit comments

Comments
 (0)