mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
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)
This commit is contained in:
@@ -2159,8 +2159,8 @@ pub struct PointeeInfo {
|
||||
/// of this function call", i.e. it is UB for the memory that this pointer points to be freed
|
||||
/// while this function is still running.
|
||||
pub size: Size,
|
||||
/// If `Some`, then the pointer is aligned as indicated.
|
||||
pub align: Option<Align>,
|
||||
/// Alignment of the pointer.
|
||||
pub align: Align,
|
||||
}
|
||||
|
||||
impl<FieldIdx: Idx, VariantIdx: Idx> LayoutData<FieldIdx, VariantIdx> {
|
||||
|
||||
@@ -289,9 +289,9 @@ fn scalar_gcc_type_at<'gcc>(
|
||||
Pointer(address_space) => {
|
||||
// If we know the alignment, pick something better than i8.
|
||||
let pointee = if let Some(pointee) = self.pointee_info_at(cx, offset)
|
||||
&& let Some(align) = pointee.align
|
||||
&& pointee.align > rustc_abi::Align::ONE
|
||||
{
|
||||
cx.type_pointee_for_align(align)
|
||||
cx.type_pointee_for_align(pointee.align)
|
||||
} else {
|
||||
cx.type_i8()
|
||||
};
|
||||
|
||||
@@ -714,9 +714,9 @@ fn scalar_load_metadata<'a, 'll, 'tcx>(
|
||||
}
|
||||
|
||||
if let Some(pointee) = layout.pointee_info_at(bx, offset)
|
||||
&& let Some(align) = pointee.align
|
||||
&& pointee.align > Align::ONE
|
||||
{
|
||||
bx.align_metadata(load, align);
|
||||
bx.align_metadata(load, pointee.align);
|
||||
}
|
||||
}
|
||||
abi::Primitive::Float(_) => {}
|
||||
|
||||
@@ -1029,7 +1029,7 @@ fn ty_and_layout_pointee_info_at(
|
||||
|
||||
let pointee_info = match *this.ty.kind() {
|
||||
ty::RawPtr(_, _) | ty::FnPtr(..) if offset.bytes() == 0 => {
|
||||
Some(PointeeInfo { safe: None, size: Size::ZERO, align: None })
|
||||
Some(PointeeInfo { safe: None, size: Size::ZERO, align: Align::ONE })
|
||||
}
|
||||
ty::Ref(_, ty, mt) if offset.bytes() == 0 => {
|
||||
tcx.layout_of(typing_env.as_query_input(ty)).ok().map(|layout| {
|
||||
@@ -1059,7 +1059,7 @@ fn ty_and_layout_pointee_info_at(
|
||||
kind = PointerKind::MutableRef { unpin };
|
||||
}
|
||||
};
|
||||
PointeeInfo { safe: Some(kind), size, align: Some(layout.align.abi) }
|
||||
PointeeInfo { safe: Some(kind), size, align: layout.align.abi }
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1081,7 +1081,7 @@ fn ty_and_layout_pointee_info_at(
|
||||
// (if we had "dereferenceable on entry", we could support this)
|
||||
size: Size::ZERO,
|
||||
|
||||
align: Some(layout.align.abi),
|
||||
align: layout.align.abi,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use std::iter;
|
||||
|
||||
use rustc_abi::Primitive::Pointer;
|
||||
use rustc_abi::{BackendRepr, ExternAbi, PointerKind, Scalar, Size};
|
||||
use rustc_abi::{Align, BackendRepr, ExternAbi, PointerKind, Scalar, Size};
|
||||
use rustc_data_structures::assert_matches;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::lang_items::LangItem;
|
||||
@@ -321,8 +321,9 @@ fn arg_attrs_for_rust_scalar<'tcx>(
|
||||
|
||||
if let Some(pointee) = drop_target_pointee_info.or_else(|| layout.pointee_info_at(&cx, offset))
|
||||
{
|
||||
if let Some(align) = pointee.align {
|
||||
attrs.pointee_align = Some(align.min(cx.tcx().sess.target.max_reliable_alignment()));
|
||||
if pointee.align > Align::ONE {
|
||||
attrs.pointee_align =
|
||||
Some(pointee.align.min(cx.tcx().sess.target.max_reliable_alignment()));
|
||||
}
|
||||
|
||||
// LLVM dereferenceable attribute has unclear semantics on the return type,
|
||||
|
||||
@@ -22,7 +22,7 @@ pub fn make_unmake_result_never(x: i32) -> i32 {
|
||||
|
||||
#[no_mangle]
|
||||
pub fn extract_control_flow_never(x: ControlFlow<&str, Never>) -> &str {
|
||||
// CHECK-LABEL: define { ptr, i64 } @extract_control_flow_never(ptr align 1 %x.0, i64 %x.1)
|
||||
// CHECK-LABEL: define { ptr, i64 } @extract_control_flow_never(ptr %x.0, i64 %x.1)
|
||||
// CHECK: start:
|
||||
// CHECK-NEXT: br label %[[next:bb.*]]
|
||||
// CHECK: [[next]]:
|
||||
|
||||
@@ -185,7 +185,7 @@ pub fn _box(x: Box<i32>) -> Box<i32> {
|
||||
// With a custom allocator, it should *not* have `noalias`. (See
|
||||
// <https://github.com/rust-lang/miri/issues/3341> for why.) The second argument is the allocator,
|
||||
// which is a reference here that still carries `noalias` as usual.
|
||||
// CHECK: @_box_custom(ptr noundef nonnull align 4 %x.0, ptr noalias noundef nonnull readonly align 1{{( captures\(address, read_provenance\))?}} %x.1)
|
||||
// CHECK: @_box_custom(ptr noundef nonnull align 4 %x.0, ptr noalias noundef nonnull readonly{{( captures\(address, read_provenance\))?}} %x.1)
|
||||
#[no_mangle]
|
||||
pub fn _box_custom(x: Box<i32, &std::alloc::Global>) {
|
||||
drop(x)
|
||||
@@ -209,14 +209,14 @@ pub fn struct_return() -> S {
|
||||
pub fn helper(_: usize) {}
|
||||
|
||||
// CHECK: @slice(
|
||||
// CHECK-SAME: ptr noalias noundef nonnull readonly align 1{{( captures\(address, read_provenance\))?}} %_1.0,
|
||||
// CHECK-SAME: ptr noalias noundef nonnull readonly{{( captures\(address, read_provenance\))?}} %_1.0,
|
||||
// CHECK-SAME: [[USIZE]] noundef range({{i32 0, -2147483648|i64 0, -9223372036854775808}}) %_1.1)
|
||||
// FIXME #25759 This should also have `nocapture`
|
||||
#[no_mangle]
|
||||
pub fn slice(_: &[u8]) {}
|
||||
|
||||
// CHECK: @mutable_slice(
|
||||
// CHECK-SAME: ptr noalias noundef nonnull align 1 %_1.0,
|
||||
// CHECK-SAME: ptr noalias noundef nonnull %_1.0,
|
||||
// CHECK-SAME: [[USIZE]] noundef range({{i32 0, -2147483648|i64 0, -9223372036854775808}}) %_1.1)
|
||||
// FIXME #25759 This should also have `nocapture`
|
||||
#[no_mangle]
|
||||
@@ -234,22 +234,22 @@ pub fn unsafe_slice(_: &[UnsafeInner]) {}
|
||||
pub fn raw_slice(_: *const [u8]) {}
|
||||
|
||||
// CHECK: @str(
|
||||
// CHECK-SAME: ptr noalias noundef nonnull readonly align 1{{( captures\(address, read_provenance\))?}} %_1.0,
|
||||
// CHECK-SAME: ptr noalias noundef nonnull readonly{{( captures\(address, read_provenance\))?}} %_1.0,
|
||||
// CHECK-SAME: [[USIZE]] noundef range({{i32 0, -2147483648|i64 0, -9223372036854775808}}) %_1.1)
|
||||
// FIXME #25759 This should also have `nocapture`
|
||||
#[no_mangle]
|
||||
pub fn str(_: &[u8]) {}
|
||||
|
||||
// CHECK: @trait_borrow(ptr noundef nonnull align 1 %_1.0, {{.+}} noalias noundef readonly align {{.*}} dereferenceable({{.*}}) %_1.1)
|
||||
// CHECK: @trait_borrow(ptr noundef nonnull %_1.0, {{.+}} noalias noundef readonly align {{.*}} dereferenceable({{.*}}) %_1.1)
|
||||
// FIXME #25759 This should also have `nocapture`
|
||||
#[no_mangle]
|
||||
pub fn trait_borrow(_: &dyn Drop) {}
|
||||
|
||||
// CHECK: @option_trait_borrow(ptr noundef align 1 %x.0, ptr %x.1)
|
||||
// CHECK: @option_trait_borrow(ptr noundef %x.0, ptr %x.1)
|
||||
#[no_mangle]
|
||||
pub fn option_trait_borrow(x: Option<&dyn Drop>) {}
|
||||
|
||||
// CHECK: @option_trait_borrow_mut(ptr noundef align 1 %x.0, ptr %x.1)
|
||||
// CHECK: @option_trait_borrow_mut(ptr noundef %x.0, ptr %x.1)
|
||||
#[no_mangle]
|
||||
pub fn option_trait_borrow_mut(x: Option<&mut dyn Drop>) {}
|
||||
|
||||
@@ -259,13 +259,13 @@ pub fn trait_raw(_: *const dyn Drop) {}
|
||||
|
||||
// Ensure that `Box` gets `noalias` when the right traits are present, but removing *either* `Unpin`
|
||||
// or `UnsafeUnpin` is enough to lose the attribute.
|
||||
// CHECK: @trait_box(ptr noalias noundef nonnull align 1{{( %0)?}}, {{.+}} noalias noundef readonly align {{.*}} dereferenceable({{.*}}){{( %1)?}})
|
||||
// CHECK: @trait_box(ptr noalias noundef nonnull{{( %0)?}}, {{.+}} noalias noundef readonly align {{.*}} dereferenceable({{.*}}){{( %1)?}})
|
||||
#[no_mangle]
|
||||
pub fn trait_box(_: Box<dyn Drop + Unpin + UnsafeUnpin>) {}
|
||||
// CHECK: @trait_box_pin1(ptr noundef nonnull align 1{{( %0)?}}, {{.+}} noalias noundef readonly align {{.*}} dereferenceable({{.*}}){{( %1)?}})
|
||||
// CHECK: @trait_box_pin1(ptr noundef nonnull{{( %0)?}}, {{.+}} noalias noundef readonly align {{.*}} dereferenceable({{.*}}){{( %1)?}})
|
||||
#[no_mangle]
|
||||
pub fn trait_box_pin1(_: Box<dyn Drop + Unpin>) {}
|
||||
// CHECK: @trait_box_pin2(ptr noundef nonnull align 1{{( %0)?}}, {{.+}} noalias noundef readonly align {{.*}} dereferenceable({{.*}}){{( %1)?}})
|
||||
// CHECK: @trait_box_pin2(ptr noundef nonnull{{( %0)?}}, {{.+}} noalias noundef readonly align {{.*}} dereferenceable({{.*}}){{( %1)?}})
|
||||
#[no_mangle]
|
||||
pub fn trait_box_pin2(_: Box<dyn Drop + UnsafeUnpin>) {}
|
||||
|
||||
@@ -281,7 +281,7 @@ pub fn trait_mutref_pin1(_: &mut (i32, dyn Drop + Unpin)) {}
|
||||
#[no_mangle]
|
||||
pub fn trait_mutref_pin2(_: &mut (i32, dyn Drop + UnsafeUnpin)) {}
|
||||
|
||||
// CHECK: { ptr, ptr } @trait_option(ptr noalias noundef align 1 %x.0, ptr %x.1)
|
||||
// CHECK: { ptr, ptr } @trait_option(ptr noalias noundef %x.0, ptr %x.1)
|
||||
#[no_mangle]
|
||||
pub fn trait_option(
|
||||
x: Option<Box<dyn Drop + Unpin + UnsafeUnpin>>,
|
||||
|
||||
@@ -76,7 +76,7 @@ impl<T, U, const N: usize> Trait5<U, N> for T {
|
||||
pub fn foo1(a: &dyn Trait1) {
|
||||
a.foo();
|
||||
// CHECK-LABEL: define{{.*}}4foo1{{.*}}!{{<unknown kind #36>|kcfi_type}} !{{[0-9]+}}
|
||||
// CHECK: call void %{{[0-9]}}(ptr align 1 {{%[a-z]\.0|%_[0-9]}}){{.*}}[ "kcfi"(i32 [[TYPE1:[[:print:]]+]]) ]
|
||||
// CHECK: call void %{{[0-9]}}(ptr {{%[a-z]\.0|%_[0-9]}}){{.*}}[ "kcfi"(i32 [[TYPE1:[[:print:]]+]]) ]
|
||||
}
|
||||
|
||||
pub fn bar1() {
|
||||
@@ -84,13 +84,13 @@ pub fn bar1() {
|
||||
let b = &a as &dyn Trait1;
|
||||
b.foo();
|
||||
// CHECK-LABEL: define{{.*}}4bar1{{.*}}!{{<unknown kind #36>|kcfi_type}} !{{[0-9]+}}
|
||||
// CHECK: call void %{{[0-9]}}(ptr align 1 {{%[a-z]\.0|%_[0-9]}}){{.*}}[ "kcfi"(i32 [[TYPE1:[[:print:]]+]]) ]
|
||||
// CHECK: call void %{{[0-9]}}(ptr {{%[a-z]\.0|%_[0-9]}}){{.*}}[ "kcfi"(i32 [[TYPE1:[[:print:]]+]]) ]
|
||||
}
|
||||
|
||||
pub fn foo2<T>(a: &dyn Trait2<T>) {
|
||||
a.bar();
|
||||
// CHECK-LABEL: define{{.*}}4foo2{{.*}}!{{<unknown kind #36>|kcfi_type}} !{{[0-9]+}}
|
||||
// CHECK: call void %{{[0-9]}}(ptr align 1 {{%[a-z]\.0|%_[0-9]}}){{.*}}[ "kcfi"(i32 [[TYPE2:[[:print:]]+]]) ]
|
||||
// CHECK: call void %{{[0-9]}}(ptr {{%[a-z]\.0|%_[0-9]}}){{.*}}[ "kcfi"(i32 [[TYPE2:[[:print:]]+]]) ]
|
||||
}
|
||||
|
||||
pub fn bar2() {
|
||||
@@ -99,14 +99,14 @@ pub fn bar2() {
|
||||
let b = &a as &dyn Trait2<i32>;
|
||||
b.bar();
|
||||
// CHECK-LABEL: define{{.*}}4bar2{{.*}}!{{<unknown kind #36>|kcfi_type}} !{{[0-9]+}}
|
||||
// CHECK: call void %{{[0-9]}}(ptr align 1 {{%[a-z]\.0|%_[0-9]}}){{.*}}[ "kcfi"(i32 [[TYPE2:[[:print:]]+]]) ]
|
||||
// CHECK: call void %{{[0-9]}}(ptr {{%[a-z]\.0|%_[0-9]}}){{.*}}[ "kcfi"(i32 [[TYPE2:[[:print:]]+]]) ]
|
||||
}
|
||||
|
||||
pub fn foo3(a: &dyn Trait3<Type3>) {
|
||||
let b = Type3;
|
||||
a.baz(&b);
|
||||
// CHECK-LABEL: define{{.*}}4foo3{{.*}}!{{<unknown kind #36>|kcfi_type}} !{{[0-9]+}}
|
||||
// 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:]]+]]) ]
|
||||
// CHECK: call void %{{[0-9]}}(ptr {{%[a-z]\.0|%_[0-9]}}, ptr {{%[a-z]\.0|%_[0-9]}}){{.*}}[ "kcfi"(i32 [[TYPE3:[[:print:]]+]]) ]
|
||||
}
|
||||
|
||||
pub fn bar3() {
|
||||
@@ -115,14 +115,14 @@ pub fn bar3() {
|
||||
let b = &a as &dyn Trait3<Type3>;
|
||||
b.baz(&a);
|
||||
// CHECK-LABEL: define{{.*}}4bar3{{.*}}!{{<unknown kind #36>|kcfi_type}} !{{[0-9]+}}
|
||||
// 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:]]+]]) ]
|
||||
// CHECK: call void %{{[0-9]}}(ptr {{%[a-z]\.0|%_[0-9]}}, ptr {{%[a-z]\.0|%_[0-9]}}){{.*}}[ "kcfi"(i32 [[TYPE3:[[:print:]]+]]) ]
|
||||
}
|
||||
|
||||
pub fn foo4<'a>(a: &dyn Trait4<'a, Type4, Output = &'a i32>) {
|
||||
let b = Type4;
|
||||
a.qux(&b);
|
||||
// CHECK-LABEL: define{{.*}}4foo4{{.*}}!{{<unknown kind #36>|kcfi_type}} !{{[0-9]+}}
|
||||
// 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:]]+]]) ]
|
||||
// CHECK: call align 4 ptr %{{[0-9]}}(ptr {{%[a-z]\.0|%_[0-9]}}, ptr {{%[a-z]\.0|%_[0-9]}}){{.*}}[ "kcfi"(i32 [[TYPE4:[[:print:]]+]]) ]
|
||||
}
|
||||
|
||||
pub fn bar4<'a>() {
|
||||
@@ -131,14 +131,14 @@ pub fn bar4<'a>() {
|
||||
let b = &a as &dyn Trait4<'a, Type4, Output = &'a i32>;
|
||||
b.qux(&a);
|
||||
// CHECK-LABEL: define{{.*}}4bar4{{.*}}!{{<unknown kind #36>|kcfi_type}} !{{[0-9]+}}
|
||||
// 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:]]+]]) ]
|
||||
// CHECK: call align 4 ptr %{{[0-9]}}(ptr {{%[a-z]\.0|%_[0-9]}}, ptr {{%[a-z]\.0|%_[0-9]}}){{.*}}[ "kcfi"(i32 [[TYPE4:[[:print:]]+]]) ]
|
||||
}
|
||||
|
||||
pub fn foo5(a: &dyn Trait5<Type5, 32>) {
|
||||
let b = &[Type5; 32];
|
||||
a.quux(&b);
|
||||
// CHECK-LABEL: define{{.*}}4foo5{{.*}}!{{<unknown kind #36>|kcfi_type}} !{{[0-9]+}}
|
||||
// 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:]]+]]) ]
|
||||
// CHECK: call void %{{[0-9]}}(ptr {{%[a-z](\.0)*|%_[0-9]+]}}, ptr {{%[a-z](\.0)*|%_[0-9]+}}){{.*}}[ "kcfi"(i32 [[TYPE5:[[:print:]]+]]) ]
|
||||
}
|
||||
|
||||
pub fn bar5() {
|
||||
@@ -147,7 +147,7 @@ pub fn bar5() {
|
||||
let b = &a as &dyn Trait5<Type5, 32>;
|
||||
b.quux(&a);
|
||||
// CHECK-LABEL: define{{.*}}4bar5{{.*}}!{{<unknown kind #36>|kcfi_type}} !{{[0-9]+}}
|
||||
// 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:]]+]]) ]
|
||||
// CHECK: call void %{{[0-9]}}(ptr {{%[a-z](\.0)*|%_[0-9]+]}}, ptr {{%[a-z](\.0)*|%_[0-9]+}}){{.*}}[ "kcfi"(i32 [[TYPE5:[[:print:]]+]]) ]
|
||||
}
|
||||
|
||||
// CHECK: !{{[0-9]+}} = !{i32 [[TYPE1]]}
|
||||
|
||||
@@ -50,7 +50,7 @@ fn make_mu_ref_uninit<'a>() -> MU<&'a u16> {
|
||||
|
||||
#[no_mangle]
|
||||
fn make_mu_str(x: &str) -> MU<&str> {
|
||||
// CHECK-LABEL: { ptr, i64 } @make_mu_str(ptr align 1 %x.0, i64 %x.1)
|
||||
// CHECK-LABEL: { ptr, i64 } @make_mu_str(ptr %x.0, i64 %x.1)
|
||||
// CHECK-NEXT: start:
|
||||
// CHECK-NEXT: %0 = insertvalue { ptr, i64 } poison, ptr %x.0, 0
|
||||
// CHECK-NEXT: %1 = insertvalue { ptr, i64 } %0, i64 %x.1, 1
|
||||
|
||||
@@ -56,7 +56,7 @@ pub fn upcast_diamond_to_a(x: &dyn Diamond) -> &dyn A {
|
||||
}
|
||||
|
||||
// CHECK-LABEL: upcast_diamond_to_b
|
||||
// CHECK-SAME: (ptr align {{[0-9]+}} [[DATA_PTR:%.+]], ptr align {{[0-9]+}} [[VTABLE_PTR:%.+]])
|
||||
// CHECK-SAME: (ptr [[DATA_PTR:%.+]], ptr align 8 [[VTABLE_PTR:%.+]])
|
||||
#[no_mangle]
|
||||
pub fn upcast_diamond_to_b(x: &dyn Diamond) -> &dyn B {
|
||||
// Requires adjustment, since it's a non-first supertrait.
|
||||
|
||||
Reference in New Issue
Block a user