Skip to content

Commit 5423cd4

Browse files
TKanXscottmcm
andcommitted
test(codegen): Add and update codegen tests for DST size_of_val assume
Co-authored-by: Scott McMurray <scottmcm@users.noreply.github.com>
1 parent 1339fe8 commit 5423cd4

2 files changed

Lines changed: 38 additions & 2 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//@ compile-flags: -Copt-level=3 -Z merge-functions=disabled
2+
//@ needs-deterministic-layouts
3+
4+
#![crate_type = "lib"]
5+
6+
// Regression test for #152788: `size_of_val(p) == 0` folds to `false` for
7+
// DSTs with a non-zero prefix (nuw+nsw on offset+tail, assume on rounding).
8+
9+
pub struct Foo<T: ?Sized>(pub [u32; 3], pub T);
10+
11+
// CHECK-LABEL: @size_of_val_dyn_not_zero
12+
#[no_mangle]
13+
pub fn size_of_val_dyn_not_zero(p: &Foo<dyn std::fmt::Debug>) -> bool {
14+
// CHECK: ret i1 false
15+
std::mem::size_of_val(p) == 0
16+
}
17+
18+
// CHECK-LABEL: @size_of_val_slice_u8_not_zero
19+
#[no_mangle]
20+
pub fn size_of_val_slice_u8_not_zero(p: &Foo<[u8]>) -> bool {
21+
// CHECK: ret i1 false
22+
std::mem::size_of_val(p) == 0
23+
}
24+
25+
// CHECK-LABEL: @size_of_val_slice_i32_not_zero
26+
#[no_mangle]
27+
pub fn size_of_val_slice_i32_not_zero(p: &Foo<[i32]>) -> bool {
28+
// CHECK: ret i1 false
29+
std::mem::size_of_val(p) == 0
30+
}

tests/codegen-llvm/dst-vtable-align-nonzero.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,13 @@ pub struct Struct<W: ?Sized> {
3030
pub fn eliminates_runtime_check_when_align_1(
3131
x: &Struct<WrapperWithAlign1<dyn Trait>>,
3232
) -> &WrapperWithAlign1<dyn Trait> {
33-
// CHECK: load [[USIZE:i[0-9]+]], {{.+}} !range [[RANGE_META:![0-9]+]]
33+
// CHECK: load [[USIZE:i[0-9]+]]
34+
// CHECK: load [[USIZE]], {{.+}} !range [[RANGE_META:![0-9]+]]
35+
// CHECK-NOT: llvm.umax
36+
// CHECK-NOT: icmp
37+
// CHECK-NOT: select
38+
// CHECK: [[ASSUME_CMP:%.+]] = icmp
39+
// CHECK-NEXT: call void @llvm.assume(i1 [[ASSUME_CMP]])
3440
// CHECK-NOT: llvm.umax
3541
// CHECK-NOT: icmp
3642
// CHECK-NOT: select
@@ -43,7 +49,7 @@ pub fn eliminates_runtime_check_when_align_1(
4349
pub fn does_not_eliminate_runtime_check_when_align_2(
4450
x: &Struct<WrapperWithAlign2<dyn Trait>>,
4551
) -> &WrapperWithAlign2<dyn Trait> {
46-
// CHECK: [[X0:%[0-9]+]] = load [[USIZE]], {{.+}} !range [[RANGE_META]]
52+
// CHECK: load [[USIZE]], {{.+}} !range [[RANGE_META]]
4753
// CHECK: {{icmp|llvm.umax}}
4854
// CHECK: ret
4955
&x.dst

0 commit comments

Comments
 (0)