Skip to content

Commit babf188

Browse files
committed
make PointeeInfo::align non-optional
Instead of defaulting to `None` it now defaults to `Align::ONE` i.e. no alignment restriction. Codegen test changes are due to us now skipping `align 1` annotations (they are useless; not skipping them makes all the raw pointers gain an `align 1` annotation which doesn't seem any good)
1 parent efbd798 commit babf188

10 files changed

Lines changed: 37 additions & 36 deletions

File tree

compiler/rustc_abi/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2159,8 +2159,8 @@ pub struct PointeeInfo {
21592159
/// of this function call", i.e. it is UB for the memory that this pointer points to be freed
21602160
/// while this function is still running.
21612161
pub size: Size,
2162-
/// If `Some`, then the pointer is aligned as indicated.
2163-
pub align: Option<Align>,
2162+
/// Alignment of the pointer.
2163+
pub align: Align,
21642164
}
21652165

21662166
impl<FieldIdx: Idx, VariantIdx: Idx> LayoutData<FieldIdx, VariantIdx> {

compiler/rustc_codegen_gcc/src/type_of.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,9 +289,9 @@ impl<'tcx> LayoutGccExt<'tcx> for TyAndLayout<'tcx> {
289289
Pointer(address_space) => {
290290
// If we know the alignment, pick something better than i8.
291291
let pointee = if let Some(pointee) = self.pointee_info_at(cx, offset)
292-
&& let Some(align) = pointee.align
292+
&& pointee.align > rustc_abi::Align::ONE
293293
{
294-
cx.type_pointee_for_align(align)
294+
cx.type_pointee_for_align(pointee.align)
295295
} else {
296296
cx.type_i8()
297297
};

compiler/rustc_codegen_llvm/src/builder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -714,9 +714,9 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
714714
}
715715

716716
if let Some(pointee) = layout.pointee_info_at(bx, offset)
717-
&& let Some(align) = pointee.align
717+
&& pointee.align > Align::ONE
718718
{
719-
bx.align_metadata(load, align);
719+
bx.align_metadata(load, pointee.align);
720720
}
721721
}
722722
abi::Primitive::Float(_) => {}

compiler/rustc_middle/src/ty/layout.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,7 @@ where
10241024

10251025
let pointee_info = match *this.ty.kind() {
10261026
ty::RawPtr(_, _) | ty::FnPtr(..) if offset.bytes() == 0 => {
1027-
Some(PointeeInfo { safe: None, size: Size::ZERO, align: None })
1027+
Some(PointeeInfo { safe: None, size: Size::ZERO, align: Align::ONE })
10281028
}
10291029
ty::Ref(_, ty, mt) if offset.bytes() == 0 => {
10301030
tcx.layout_of(typing_env.as_query_input(ty)).ok().map(|layout| {
@@ -1059,7 +1059,7 @@ where
10591059
PointerKind::MutableRef { unpin }
10601060
}
10611061
};
1062-
PointeeInfo { safe: Some(kind), size, align: Some(layout.align.abi) }
1062+
PointeeInfo { safe: Some(kind), size, align: layout.align.abi }
10631063
})
10641064
}
10651065

@@ -1082,7 +1082,7 @@ where
10821082
// (if we had "dereferenceable on entry", we could support this)
10831083
size: Size::ZERO,
10841084

1085-
align: Some(layout.align.abi),
1085+
align: layout.align.abi,
10861086
})
10871087
}
10881088

compiler/rustc_ty_utils/src/abi.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::iter;
22

33
use rustc_abi::Primitive::Pointer;
4-
use rustc_abi::{BackendRepr, ExternAbi, PointerKind, Scalar, Size};
4+
use rustc_abi::{Align, BackendRepr, ExternAbi, PointerKind, Scalar, Size};
55
use rustc_data_structures::assert_matches;
66
use rustc_hir as hir;
77
use rustc_hir::lang_items::LangItem;
@@ -313,8 +313,9 @@ fn arg_attrs_for_rust_scalar<'tcx>(
313313

314314
if let Some(pointee) = drop_target_pointee_info.or_else(|| layout.pointee_info_at(&cx, offset))
315315
{
316-
if let Some(align) = pointee.align {
317-
attrs.pointee_align = Some(align.min(cx.tcx().sess.target.max_reliable_alignment()));
316+
if pointee.align > Align::ONE {
317+
attrs.pointee_align =
318+
Some(pointee.align.min(cx.tcx().sess.target.max_reliable_alignment()));
318319
}
319320

320321
// LLVM dereferenceable attribute has unclear semantics on the return type,

tests/codegen-llvm/enum/enum-transparent-extract.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub fn make_unmake_result_never(x: i32) -> i32 {
2222

2323
#[no_mangle]
2424
pub fn extract_control_flow_never(x: ControlFlow<&str, Never>) -> &str {
25-
// CHECK-LABEL: define { ptr, i64 } @extract_control_flow_never(ptr align 1 %x.0, i64 %x.1)
25+
// CHECK-LABEL: define { ptr, i64 } @extract_control_flow_never(ptr %x.0, i64 %x.1)
2626
// CHECK: start:
2727
// CHECK-NEXT: br label %[[next:bb.*]]
2828
// CHECK: [[next]]:

tests/codegen-llvm/function-arguments.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ pub fn _box(x: Box<i32>) -> Box<i32> {
185185
// With a custom allocator, it should *not* have `noalias`. (See
186186
// <https://github.com/rust-lang/miri/issues/3341> for why.) The second argument is the allocator,
187187
// which is a reference here that still carries `noalias` as usual.
188-
// CHECK: @_box_custom(ptr noundef nonnull align 4 %x.0, ptr noalias noundef nonnull readonly align 1{{( captures\(address, read_provenance\))?}} %x.1)
188+
// CHECK: @_box_custom(ptr noundef nonnull align 4 %x.0, ptr noalias noundef nonnull readonly{{( captures\(address, read_provenance\))?}} %x.1)
189189
#[no_mangle]
190190
pub fn _box_custom(x: Box<i32, &std::alloc::Global>) {
191191
drop(x)
@@ -209,14 +209,14 @@ pub fn struct_return() -> S {
209209
pub fn helper(_: usize) {}
210210

211211
// CHECK: @slice(
212-
// CHECK-SAME: ptr noalias noundef nonnull readonly align 1{{( captures\(address, read_provenance\))?}} %_1.0,
212+
// CHECK-SAME: ptr noalias noundef nonnull readonly{{( captures\(address, read_provenance\))?}} %_1.0,
213213
// CHECK-SAME: [[USIZE]] noundef range({{i32 0, -2147483648|i64 0, -9223372036854775808}}) %_1.1)
214214
// FIXME #25759 This should also have `nocapture`
215215
#[no_mangle]
216216
pub fn slice(_: &[u8]) {}
217217

218218
// CHECK: @mutable_slice(
219-
// CHECK-SAME: ptr noalias noundef nonnull align 1 %_1.0,
219+
// CHECK-SAME: ptr noalias noundef nonnull %_1.0,
220220
// CHECK-SAME: [[USIZE]] noundef range({{i32 0, -2147483648|i64 0, -9223372036854775808}}) %_1.1)
221221
// FIXME #25759 This should also have `nocapture`
222222
#[no_mangle]
@@ -234,22 +234,22 @@ pub fn unsafe_slice(_: &[UnsafeInner]) {}
234234
pub fn raw_slice(_: *const [u8]) {}
235235

236236
// CHECK: @str(
237-
// CHECK-SAME: ptr noalias noundef nonnull readonly align 1{{( captures\(address, read_provenance\))?}} %_1.0,
237+
// CHECK-SAME: ptr noalias noundef nonnull readonly{{( captures\(address, read_provenance\))?}} %_1.0,
238238
// CHECK-SAME: [[USIZE]] noundef range({{i32 0, -2147483648|i64 0, -9223372036854775808}}) %_1.1)
239239
// FIXME #25759 This should also have `nocapture`
240240
#[no_mangle]
241241
pub fn str(_: &[u8]) {}
242242

243-
// CHECK: @trait_borrow(ptr noundef nonnull align 1 %_1.0, {{.+}} noalias noundef readonly align {{.*}} dereferenceable({{.*}}) %_1.1)
243+
// CHECK: @trait_borrow(ptr noundef nonnull %_1.0, {{.+}} noalias noundef readonly align {{.*}} dereferenceable({{.*}}) %_1.1)
244244
// FIXME #25759 This should also have `nocapture`
245245
#[no_mangle]
246246
pub fn trait_borrow(_: &dyn Drop) {}
247247

248-
// CHECK: @option_trait_borrow(ptr noundef align 1 %x.0, ptr %x.1)
248+
// CHECK: @option_trait_borrow(ptr noundef %x.0, ptr %x.1)
249249
#[no_mangle]
250250
pub fn option_trait_borrow(x: Option<&dyn Drop>) {}
251251

252-
// CHECK: @option_trait_borrow_mut(ptr noundef align 1 %x.0, ptr %x.1)
252+
// CHECK: @option_trait_borrow_mut(ptr noundef %x.0, ptr %x.1)
253253
#[no_mangle]
254254
pub fn option_trait_borrow_mut(x: Option<&mut dyn Drop>) {}
255255

@@ -259,13 +259,13 @@ pub fn trait_raw(_: *const dyn Drop) {}
259259

260260
// Ensure that `Box` gets `noalias` when the right traits are present, but removing *either* `Unpin`
261261
// or `UnsafeUnpin` is enough to lose the attribute.
262-
// CHECK: @trait_box(ptr noalias noundef nonnull align 1{{( %0)?}}, {{.+}} noalias noundef readonly align {{.*}} dereferenceable({{.*}}){{( %1)?}})
262+
// CHECK: @trait_box(ptr noalias noundef nonnull{{( %0)?}}, {{.+}} noalias noundef readonly align {{.*}} dereferenceable({{.*}}){{( %1)?}})
263263
#[no_mangle]
264264
pub fn trait_box(_: Box<dyn Drop + Unpin + UnsafeUnpin>) {}
265-
// CHECK: @trait_box_pin1(ptr noundef nonnull align 1{{( %0)?}}, {{.+}} noalias noundef readonly align {{.*}} dereferenceable({{.*}}){{( %1)?}})
265+
// CHECK: @trait_box_pin1(ptr noundef nonnull{{( %0)?}}, {{.+}} noalias noundef readonly align {{.*}} dereferenceable({{.*}}){{( %1)?}})
266266
#[no_mangle]
267267
pub fn trait_box_pin1(_: Box<dyn Drop + Unpin>) {}
268-
// CHECK: @trait_box_pin2(ptr noundef nonnull align 1{{( %0)?}}, {{.+}} noalias noundef readonly align {{.*}} dereferenceable({{.*}}){{( %1)?}})
268+
// CHECK: @trait_box_pin2(ptr noundef nonnull{{( %0)?}}, {{.+}} noalias noundef readonly align {{.*}} dereferenceable({{.*}}){{( %1)?}})
269269
#[no_mangle]
270270
pub fn trait_box_pin2(_: Box<dyn Drop + UnsafeUnpin>) {}
271271

@@ -281,7 +281,7 @@ pub fn trait_mutref_pin1(_: &mut (i32, dyn Drop + Unpin)) {}
281281
#[no_mangle]
282282
pub fn trait_mutref_pin2(_: &mut (i32, dyn Drop + UnsafeUnpin)) {}
283283

284-
// CHECK: { ptr, ptr } @trait_option(ptr noalias noundef align 1 %x.0, ptr %x.1)
284+
// CHECK: { ptr, ptr } @trait_option(ptr noalias noundef %x.0, ptr %x.1)
285285
#[no_mangle]
286286
pub fn trait_option(
287287
x: Option<Box<dyn Drop + Unpin + UnsafeUnpin>>,

tests/codegen-llvm/sanitizer/kcfi/emit-type-metadata-trait-objects.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,21 +76,21 @@ impl<T, U, const N: usize> Trait5<U, N> for T {
7676
pub fn foo1(a: &dyn Trait1) {
7777
a.foo();
7878
// CHECK-LABEL: define{{.*}}4foo1{{.*}}!{{<unknown kind #36>|kcfi_type}} !{{[0-9]+}}
79-
// CHECK: call void %{{[0-9]}}(ptr align 1 {{%[a-z]\.0|%_[0-9]}}){{.*}}[ "kcfi"(i32 [[TYPE1:[[:print:]]+]]) ]
79+
// CHECK: call void %{{[0-9]}}(ptr {{%[a-z]\.0|%_[0-9]}}){{.*}}[ "kcfi"(i32 [[TYPE1:[[:print:]]+]]) ]
8080
}
8181

8282
pub fn bar1() {
8383
let a = Type1;
8484
let b = &a as &dyn Trait1;
8585
b.foo();
8686
// CHECK-LABEL: define{{.*}}4bar1{{.*}}!{{<unknown kind #36>|kcfi_type}} !{{[0-9]+}}
87-
// CHECK: call void %{{[0-9]}}(ptr align 1 {{%[a-z]\.0|%_[0-9]}}){{.*}}[ "kcfi"(i32 [[TYPE1:[[:print:]]+]]) ]
87+
// CHECK: call void %{{[0-9]}}(ptr {{%[a-z]\.0|%_[0-9]}}){{.*}}[ "kcfi"(i32 [[TYPE1:[[:print:]]+]]) ]
8888
}
8989

9090
pub fn foo2<T>(a: &dyn Trait2<T>) {
9191
a.bar();
9292
// CHECK-LABEL: define{{.*}}4foo2{{.*}}!{{<unknown kind #36>|kcfi_type}} !{{[0-9]+}}
93-
// CHECK: call void %{{[0-9]}}(ptr align 1 {{%[a-z]\.0|%_[0-9]}}){{.*}}[ "kcfi"(i32 [[TYPE2:[[:print:]]+]]) ]
93+
// CHECK: call void %{{[0-9]}}(ptr {{%[a-z]\.0|%_[0-9]}}){{.*}}[ "kcfi"(i32 [[TYPE2:[[:print:]]+]]) ]
9494
}
9595

9696
pub fn bar2() {
@@ -99,14 +99,14 @@ pub fn bar2() {
9999
let b = &a as &dyn Trait2<i32>;
100100
b.bar();
101101
// CHECK-LABEL: define{{.*}}4bar2{{.*}}!{{<unknown kind #36>|kcfi_type}} !{{[0-9]+}}
102-
// CHECK: call void %{{[0-9]}}(ptr align 1 {{%[a-z]\.0|%_[0-9]}}){{.*}}[ "kcfi"(i32 [[TYPE2:[[:print:]]+]]) ]
102+
// CHECK: call void %{{[0-9]}}(ptr {{%[a-z]\.0|%_[0-9]}}){{.*}}[ "kcfi"(i32 [[TYPE2:[[:print:]]+]]) ]
103103
}
104104

105105
pub fn foo3(a: &dyn Trait3<Type3>) {
106106
let b = Type3;
107107
a.baz(&b);
108108
// CHECK-LABEL: define{{.*}}4foo3{{.*}}!{{<unknown kind #36>|kcfi_type}} !{{[0-9]+}}
109-
// CHECK: call void %{{[0-9]}}(ptr align 1 {{%[a-z]\.0|%_[0-9]}}, ptr align 1 {{%[a-z]\.0|%_[0-9]}}){{.*}}[ "kcfi"(i32 [[TYPE3:[[:print:]]+]]) ]
109+
// CHECK: call void %{{[0-9]}}(ptr {{%[a-z]\.0|%_[0-9]}}, ptr {{%[a-z]\.0|%_[0-9]}}){{.*}}[ "kcfi"(i32 [[TYPE3:[[:print:]]+]]) ]
110110
}
111111

112112
pub fn bar3() {
@@ -115,14 +115,14 @@ pub fn bar3() {
115115
let b = &a as &dyn Trait3<Type3>;
116116
b.baz(&a);
117117
// CHECK-LABEL: define{{.*}}4bar3{{.*}}!{{<unknown kind #36>|kcfi_type}} !{{[0-9]+}}
118-
// CHECK: call void %{{[0-9]}}(ptr align 1 {{%[a-z]\.0|%_[0-9]}}, ptr align 1 {{%[a-z]\.0|%_[0-9]}}){{.*}}[ "kcfi"(i32 [[TYPE3:[[:print:]]+]]) ]
118+
// CHECK: call void %{{[0-9]}}(ptr {{%[a-z]\.0|%_[0-9]}}, ptr {{%[a-z]\.0|%_[0-9]}}){{.*}}[ "kcfi"(i32 [[TYPE3:[[:print:]]+]]) ]
119119
}
120120

121121
pub fn foo4<'a>(a: &dyn Trait4<'a, Type4, Output = &'a i32>) {
122122
let b = Type4;
123123
a.qux(&b);
124124
// CHECK-LABEL: define{{.*}}4foo4{{.*}}!{{<unknown kind #36>|kcfi_type}} !{{[0-9]+}}
125-
// CHECK: call align 4 ptr %{{[0-9]}}(ptr align 1 {{%[a-z]\.0|%_[0-9]}}, ptr align 1 {{%[a-z]\.0|%_[0-9]}}){{.*}}[ "kcfi"(i32 [[TYPE4:[[:print:]]+]]) ]
125+
// CHECK: call align 4 ptr %{{[0-9]}}(ptr {{%[a-z]\.0|%_[0-9]}}, ptr {{%[a-z]\.0|%_[0-9]}}){{.*}}[ "kcfi"(i32 [[TYPE4:[[:print:]]+]]) ]
126126
}
127127

128128
pub fn bar4<'a>() {
@@ -131,14 +131,14 @@ pub fn bar4<'a>() {
131131
let b = &a as &dyn Trait4<'a, Type4, Output = &'a i32>;
132132
b.qux(&a);
133133
// CHECK-LABEL: define{{.*}}4bar4{{.*}}!{{<unknown kind #36>|kcfi_type}} !{{[0-9]+}}
134-
// CHECK: call align 4 ptr %{{[0-9]}}(ptr align 1 {{%[a-z]\.0|%_[0-9]}}, ptr align 1 {{%[a-z]\.0|%_[0-9]}}){{.*}}[ "kcfi"(i32 [[TYPE4:[[:print:]]+]]) ]
134+
// CHECK: call align 4 ptr %{{[0-9]}}(ptr {{%[a-z]\.0|%_[0-9]}}, ptr {{%[a-z]\.0|%_[0-9]}}){{.*}}[ "kcfi"(i32 [[TYPE4:[[:print:]]+]]) ]
135135
}
136136

137137
pub fn foo5(a: &dyn Trait5<Type5, 32>) {
138138
let b = &[Type5; 32];
139139
a.quux(&b);
140140
// CHECK-LABEL: define{{.*}}4foo5{{.*}}!{{<unknown kind #36>|kcfi_type}} !{{[0-9]+}}
141-
// CHECK: call void %{{[0-9]}}(ptr align 1 {{%[a-z](\.0)*|%_[0-9]+]}}, ptr align 1 {{%[a-z](\.0)*|%_[0-9]+}}){{.*}}[ "kcfi"(i32 [[TYPE5:[[:print:]]+]]) ]
141+
// CHECK: call void %{{[0-9]}}(ptr {{%[a-z](\.0)*|%_[0-9]+]}}, ptr {{%[a-z](\.0)*|%_[0-9]+}}){{.*}}[ "kcfi"(i32 [[TYPE5:[[:print:]]+]]) ]
142142
}
143143

144144
pub fn bar5() {
@@ -147,7 +147,7 @@ pub fn bar5() {
147147
let b = &a as &dyn Trait5<Type5, 32>;
148148
b.quux(&a);
149149
// CHECK-LABEL: define{{.*}}4bar5{{.*}}!{{<unknown kind #36>|kcfi_type}} !{{[0-9]+}}
150-
// CHECK: call void %{{[0-9]}}(ptr align 1 {{%[a-z](\.0)*|%_[0-9]+]}}, ptr align 1 {{%[a-z](\.0)*|%_[0-9]+}}){{.*}}[ "kcfi"(i32 [[TYPE5:[[:print:]]+]]) ]
150+
// CHECK: call void %{{[0-9]}}(ptr {{%[a-z](\.0)*|%_[0-9]+]}}, ptr {{%[a-z](\.0)*|%_[0-9]+}}){{.*}}[ "kcfi"(i32 [[TYPE5:[[:print:]]+]]) ]
151151
}
152152

153153
// CHECK: !{{[0-9]+}} = !{i32 [[TYPE1]]}

tests/codegen-llvm/union-aggregate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ fn make_mu_ref_uninit<'a>() -> MU<&'a u16> {
5050

5151
#[no_mangle]
5252
fn make_mu_str(x: &str) -> MU<&str> {
53-
// CHECK-LABEL: { ptr, i64 } @make_mu_str(ptr align 1 %x.0, i64 %x.1)
53+
// CHECK-LABEL: { ptr, i64 } @make_mu_str(ptr %x.0, i64 %x.1)
5454
// CHECK-NEXT: start:
5555
// CHECK-NEXT: %0 = insertvalue { ptr, i64 } poison, ptr %x.0, 0
5656
// CHECK-NEXT: %1 = insertvalue { ptr, i64 } %0, i64 %x.1, 1

tests/codegen-llvm/vtable-upcast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pub fn upcast_diamond_to_a(x: &dyn Diamond) -> &dyn A {
5656
}
5757

5858
// CHECK-LABEL: upcast_diamond_to_b
59-
// CHECK-SAME: (ptr align {{[0-9]+}} [[DATA_PTR:%.+]], ptr align {{[0-9]+}} [[VTABLE_PTR:%.+]])
59+
// CHECK-SAME: (ptr [[DATA_PTR:%.+]], ptr align 8 [[VTABLE_PTR:%.+]])
6060
#[no_mangle]
6161
pub fn upcast_diamond_to_b(x: &dyn Diamond) -> &dyn B {
6262
// Requires adjustment, since it's a non-first supertrait.

0 commit comments

Comments
 (0)