diff --git a/compiler/rustc_codegen_ssa/src/mir/place.rs b/compiler/rustc_codegen_ssa/src/mir/place.rs index 6b59ea13d413..fda3d97a1c63 100644 --- a/compiler/rustc_codegen_ssa/src/mir/place.rs +++ b/compiler/rustc_codegen_ssa/src/mir/place.rs @@ -136,13 +136,14 @@ impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> { }; // If this field is a primitive type of a newtype, propogate the scalar valid range - let scalar_valid_range = if let (0, Variants::Single { .. }, Abi::Scalar(_)) = - (offset.bytes(), &self.layout.variants, field.abi) - { - self.scalar_valid_range - } else { - field.abi.scalar_valid_range(bx) - }; + let scalar_valid_range = + if let (0, Variants::Single { .. }, Abi::Scalar(_) | Abi::ScalarPair(..)) = + (offset.bytes(), &self.layout.variants, field.abi) + { + self.scalar_valid_range + } else { + field.abi.scalar_valid_range(bx) + }; PlaceRef { // HACK(eddyb): have to bitcast pointers until LLVM removes pointee types. diff --git a/src/test/codegen/scalar-ranges-newtypes.rs b/src/test/codegen/scalar-ranges-newtypes.rs index 7592d6cd2e20..e715bdd1bd1c 100644 --- a/src/test/codegen/scalar-ranges-newtypes.rs +++ b/src/test/codegen/scalar-ranges-newtypes.rs @@ -15,9 +15,14 @@ pub struct NonNull3 { ptr: *const (), } +trait Foo {} + +#[rustc_layout_scalar_valid_range_start(1)] +pub struct NonNull4(*const dyn Foo); + // CHECK: define void @test_nonnull_load #[no_mangle] -pub fn test_nonnull_load(p1: &NonNull1, p2: &NonNull2, p3: &NonNull3) { +pub fn test_nonnull_load(p1: &NonNull1, p2: &NonNull2, p3: &NonNull3, p4: &NonNull4) { // CHECK: %[[P1:[0-9]+]] = bitcast i8** %p1 to {}** // CHECK: load {}*, {}** %[[P1]], align 8, !nonnull std::hint::black_box(p1.0); @@ -29,6 +34,13 @@ pub fn test_nonnull_load(p1: &NonNull1, p2: &NonNull2, p3: &NonNull3) { // CHECK: %[[P3:[0-9]+]] = bitcast i8** %p3 to {}** // CHECK: load {}*, {}** %[[P3]], align 8, !nonnull std::hint::black_box(p3.ptr); + + // CHECK: %[[P4_PTR:[0-9]+]] = bitcast { i8*, i64* }* %p4 to {}** + // CHECK: load {}*, {}** %[[P4_PTR]], align 8, !nonnull + // CHECK: %[[P4_VTABLE:[0-9]+]] = getelementptr inbounds { i8*, i64* }, { i8*, i64* }* %p4, i64 0, i32 1 + // CHECK: %[[P4_VTABLE_PTR:[0-9]+]] = bitcast i64** %[[P4_VTABLE]] to [3 x i64]** + // CHECK: load [3 x i64]*, [3 x i64]** %[[P4_VTABLE_PTR]], align 8, !nonnull + std::hint::black_box(p4.0); } #[rustc_layout_scalar_valid_range_start(16)]