Skip to content

Commit a184e09

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 a184e09

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
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+
}

0 commit comments

Comments
 (0)