mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 23:34:48 +00:00
8ebd307d2a
For the former, it's fine for `inbounds` offsets to be one-past-the-end, so it's okay even if the ZST is the last field in the layout: > The base pointer has an in bounds address of an allocated object, > which means that it points into an allocated object, or to its end. https://llvm.org/docs/LangRef.html#getelementptr-instruction For the latter, even DST fields must always be inside the layout (or to its end for ZSTs), so using inbounds is also fine there.
44 lines
1.2 KiB
Rust
44 lines
1.2 KiB
Rust
//@ compile-flags: -C no-prepopulate-passes -Copt-level=0
|
|
|
|
#![crate_type = "lib"]
|
|
#![feature(repr_simd)]
|
|
|
|
// Hack to get the correct size for the length part in slices
|
|
// CHECK: @helper([[USIZE:i[0-9]+]] %_1)
|
|
#[no_mangle]
|
|
pub fn helper(_: usize) {
|
|
}
|
|
|
|
// Check that we correctly generate a GEP for a ZST that is not included in Scalar layout
|
|
// CHECK-LABEL: @scalar_layout
|
|
#[no_mangle]
|
|
pub fn scalar_layout(s: &(u64, ())) {
|
|
// CHECK: getelementptr inbounds i8, {{.+}}, [[USIZE]] 8
|
|
let x = &s.1;
|
|
witness(&x); // keep variable in an alloca
|
|
}
|
|
|
|
// Check that we correctly generate a GEP for a ZST that is not included in ScalarPair layout
|
|
// CHECK-LABEL: @scalarpair_layout
|
|
#[no_mangle]
|
|
pub fn scalarpair_layout(s: &(u64, u32, ())) {
|
|
// CHECK: getelementptr inbounds i8, {{.+}}, [[USIZE]] 12
|
|
let x = &s.2;
|
|
witness(&x); // keep variable in an alloca
|
|
}
|
|
|
|
#[repr(simd)]
|
|
pub struct U64x4(u64, u64, u64, u64);
|
|
|
|
// Check that we correctly generate a GEP for a ZST that is not included in Vector layout
|
|
// CHECK-LABEL: @vector_layout
|
|
#[no_mangle]
|
|
pub fn vector_layout(s: &(U64x4, ())) {
|
|
// CHECK: getelementptr inbounds i8, {{.+}}, [[USIZE]] 32
|
|
let x = &s.1;
|
|
witness(&x); // keep variable in an alloca
|
|
}
|
|
|
|
#[inline(never)]
|
|
fn witness(_: &impl Sized) {}
|