Skip to content

Commit 34a80f0

Browse files
committed
Also preserve valid scalar ranges for newtyped ScalarPair's.
1 parent 8477376 commit 34a80f0

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

compiler/rustc_codegen_ssa/src/mir/place.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,14 @@ impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> {
136136
};
137137

138138
// If this field is a primitive type of a newtype, propogate the scalar valid range
139-
let scalar_valid_range = if let (0, Variants::Single { .. }, Abi::Scalar(_)) =
140-
(offset.bytes(), &self.layout.variants, field.abi)
141-
{
142-
self.scalar_valid_range
143-
} else {
144-
field.abi.scalar_valid_range(bx)
145-
};
139+
let scalar_valid_range =
140+
if let (0, Variants::Single { .. }, Abi::Scalar(_) | Abi::ScalarPair(..)) =
141+
(offset.bytes(), &self.layout.variants, field.abi)
142+
{
143+
self.scalar_valid_range
144+
} else {
145+
field.abi.scalar_valid_range(bx)
146+
};
146147

147148
PlaceRef {
148149
// HACK(eddyb): have to bitcast pointers until LLVM removes pointee types.

src/test/codegen/scalar-ranges-newtypes.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,14 @@ pub struct NonNull3 {
1515
ptr: *const (),
1616
}
1717

18+
trait Foo {}
19+
20+
#[rustc_layout_scalar_valid_range_start(1)]
21+
pub struct NonNull4(*const dyn Foo);
22+
1823
// CHECK: define void @test_nonnull_load
1924
#[no_mangle]
20-
pub fn test_nonnull_load(p1: &NonNull1, p2: &NonNull2, p3: &NonNull3) {
25+
pub fn test_nonnull_load(p1: &NonNull1, p2: &NonNull2, p3: &NonNull3, p4: &NonNull4) {
2126
// CHECK: %[[P1:[0-9]+]] = bitcast i8** %p1 to {}**
2227
// CHECK: load {}*, {}** %[[P1]], align 8, !nonnull
2328
std::hint::black_box(p1.0);
@@ -29,6 +34,13 @@ pub fn test_nonnull_load(p1: &NonNull1, p2: &NonNull2, p3: &NonNull3) {
2934
// CHECK: %[[P3:[0-9]+]] = bitcast i8** %p3 to {}**
3035
// CHECK: load {}*, {}** %[[P3]], align 8, !nonnull
3136
std::hint::black_box(p3.ptr);
37+
38+
// CHECK: %[[P4_PTR:[0-9]+]] = bitcast { i8*, i64* }* %p4 to {}**
39+
// CHECK: load {}*, {}** %[[P4_PTR]], align 8, !nonnull
40+
// CHECK: %[[P4_VTABLE:[0-9]+]] = getelementptr inbounds { i8*, i64* }, { i8*, i64* }* %p4, i64 0, i32 1
41+
// CHECK: %[[P4_VTABLE_PTR:[0-9]+]] = bitcast i64** %[[P4_VTABLE]] to [3 x i64]**
42+
// CHECK: load [3 x i64]*, [3 x i64]** %[[P4_VTABLE_PTR]], align 8, !nonnull
43+
std::hint::black_box(p4.0);
3244
}
3345

3446
#[rustc_layout_scalar_valid_range_start(16)]

0 commit comments

Comments
 (0)