Skip to content

Commit ee4b7f6

Browse files
committed
Auto merge of #152685 - scottmcm:smaller-alignment-change, r=<try>
Update `exchange_malloc` to take `Alignment` too
2 parents 1396514 + 953e0dd commit ee4b7f6

14 files changed

Lines changed: 62 additions & 69 deletions

compiler/rustc_hir/src/lang_items.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ language_item_table! {
157157
PointeeSized, sym::pointee_sized, pointee_sized_trait, Target::Trait, GenericRequirement::Exact(0);
158158
Unsize, sym::unsize, unsize_trait, Target::Trait, GenericRequirement::Minimum(1);
159159
AlignOf, sym::mem_align_const, align_const, Target::AssocConst, GenericRequirement::Exact(0);
160+
AlignmentOf, sym::mem_alignment_const, alignment_const, Target::AssocConst, GenericRequirement::Exact(0);
160161
SizeOf, sym::mem_size_const, size_const, Target::AssocConst, GenericRequirement::Exact(0);
161162
OffsetOf, sym::offset_of, offset_of, Target::Fn, GenericRequirement::Exact(1);
162163
/// Trait injected by `#[derive(PartialEq)]`, (i.e. "Partial EQ").

compiler/rustc_mir_build/src/builder/expr/as_rvalue.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
132132
let size = tcx.require_lang_item(LangItem::SizeOf, expr_span);
133133
let size = Operand::unevaluated_constant(tcx, size, &[value_ty.into()], expr_span);
134134

135-
let align = tcx.require_lang_item(LangItem::AlignOf, expr_span);
135+
let align = tcx.require_lang_item(LangItem::AlignmentOf, expr_span);
136136
let align =
137137
Operand::unevaluated_constant(tcx, align, &[value_ty.into()], expr_span);
138138

compiler/rustc_span/src/symbol.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1445,6 +1445,7 @@ symbols! {
14451445
maybe_uninit_zeroed,
14461446
mem_align_const,
14471447
mem_align_of,
1448+
mem_alignment_const,
14481449
mem_discriminant,
14491450
mem_drop,
14501451
mem_forget,

library/alloc/src/alloc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,8 +484,8 @@ unsafe impl const Allocator for Global {
484484
#[lang = "exchange_malloc"]
485485
#[inline]
486486
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
487-
unsafe fn exchange_malloc(size: usize, align: usize) -> *mut u8 {
488-
let layout = unsafe { Layout::from_size_align_unchecked(size, align) };
487+
unsafe fn exchange_malloc(size: usize, align: Alignment) -> *mut u8 {
488+
let layout = unsafe { Layout::from_size_alignment_unchecked(size, align) };
489489
match Global.allocate(layout) {
490490
Ok(ptr) => ptr.as_mut_ptr(),
491491
Err(_) => handle_alloc_error(layout),

library/core/src/mem/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1260,6 +1260,7 @@ pub trait SizedTypeProperties: Sized {
12601260

12611261
#[doc(hidden)]
12621262
#[unstable(feature = "ptr_alignment_type", issue = "102070")]
1263+
#[lang = "mem_alignment_const"]
12631264
const ALIGNMENT: Alignment = {
12641265
// This can't panic since type alignment is always a power of two.
12651266
Alignment::new(Self::ALIGN).unwrap()
@@ -1300,7 +1301,7 @@ pub trait SizedTypeProperties: Sized {
13001301
// SAFETY: if the type is instantiated, rustc already ensures that its
13011302
// layout is valid. Use the unchecked constructor to avoid inserting a
13021303
// panicking codepath that needs to be optimized out.
1303-
unsafe { Layout::from_size_align_unchecked(Self::SIZE, Self::ALIGN) }
1304+
unsafe { Layout::from_size_alignment_unchecked(Self::SIZE, Self::ALIGNMENT) }
13041305
};
13051306

13061307
/// The largest safe length for a `[Self]`.

tests/mir-opt/box_expr.main.ElaborateDrops.diff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
bb0: {
1919
StorageLive(_1);
20-
_2 = alloc::alloc::exchange_malloc(const <S as std::mem::SizedTypeProperties>::SIZE, const <S as std::mem::SizedTypeProperties>::ALIGN) -> [return: bb1, unwind continue];
20+
_2 = alloc::alloc::exchange_malloc(const <S as std::mem::SizedTypeProperties>::SIZE, const <S as std::mem::SizedTypeProperties>::ALIGNMENT) -> [return: bb1, unwind continue];
2121
}
2222

2323
bb1: {

tests/mir-opt/building/uniform_array_move_out.move_out_by_subslice.built.after.mir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ fn move_out_by_subslice() -> () {
2020
bb0: {
2121
StorageLive(_1);
2222
StorageLive(_2);
23-
_3 = alloc::alloc::exchange_malloc(const <i32 as std::mem::SizedTypeProperties>::SIZE, const <i32 as std::mem::SizedTypeProperties>::ALIGN) -> [return: bb1, unwind: bb13];
23+
_3 = alloc::alloc::exchange_malloc(const <i32 as std::mem::SizedTypeProperties>::SIZE, const <i32 as std::mem::SizedTypeProperties>::ALIGNMENT) -> [return: bb1, unwind: bb13];
2424
}
2525

2626
bb1: {
@@ -34,7 +34,7 @@ fn move_out_by_subslice() -> () {
3434
bb2: {
3535
StorageDead(_4);
3636
StorageLive(_5);
37-
_6 = alloc::alloc::exchange_malloc(const <i32 as std::mem::SizedTypeProperties>::SIZE, const <i32 as std::mem::SizedTypeProperties>::ALIGN) -> [return: bb3, unwind: bb12];
37+
_6 = alloc::alloc::exchange_malloc(const <i32 as std::mem::SizedTypeProperties>::SIZE, const <i32 as std::mem::SizedTypeProperties>::ALIGNMENT) -> [return: bb3, unwind: bb12];
3838
}
3939

4040
bb3: {

tests/mir-opt/building/uniform_array_move_out.move_out_from_end.built.after.mir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ fn move_out_from_end() -> () {
2020
bb0: {
2121
StorageLive(_1);
2222
StorageLive(_2);
23-
_3 = alloc::alloc::exchange_malloc(const <i32 as std::mem::SizedTypeProperties>::SIZE, const <i32 as std::mem::SizedTypeProperties>::ALIGN) -> [return: bb1, unwind: bb13];
23+
_3 = alloc::alloc::exchange_malloc(const <i32 as std::mem::SizedTypeProperties>::SIZE, const <i32 as std::mem::SizedTypeProperties>::ALIGNMENT) -> [return: bb1, unwind: bb13];
2424
}
2525

2626
bb1: {
@@ -34,7 +34,7 @@ fn move_out_from_end() -> () {
3434
bb2: {
3535
StorageDead(_4);
3636
StorageLive(_5);
37-
_6 = alloc::alloc::exchange_malloc(const <i32 as std::mem::SizedTypeProperties>::SIZE, const <i32 as std::mem::SizedTypeProperties>::ALIGN) -> [return: bb3, unwind: bb12];
37+
_6 = alloc::alloc::exchange_malloc(const <i32 as std::mem::SizedTypeProperties>::SIZE, const <i32 as std::mem::SizedTypeProperties>::ALIGNMENT) -> [return: bb3, unwind: bb12];
3838
}
3939

4040
bb3: {

tests/mir-opt/const_prop/boxes.main.GVN.panic-abort.diff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
- StorageLive(_2);
2323
+ nop;
2424
StorageLive(_3);
25-
_4 = alloc::alloc::exchange_malloc(const <i32 as std::mem::SizedTypeProperties>::SIZE, const <i32 as std::mem::SizedTypeProperties>::ALIGN) -> [return: bb1, unwind unreachable];
25+
_4 = alloc::alloc::exchange_malloc(const <i32 as std::mem::SizedTypeProperties>::SIZE, const <i32 as std::mem::SizedTypeProperties>::ALIGNMENT) -> [return: bb1, unwind unreachable];
2626
}
2727

2828
bb1: {

tests/mir-opt/const_prop/boxes.main.GVN.panic-unwind.diff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
- StorageLive(_2);
2323
+ nop;
2424
StorageLive(_3);
25-
_4 = alloc::alloc::exchange_malloc(const <i32 as std::mem::SizedTypeProperties>::SIZE, const <i32 as std::mem::SizedTypeProperties>::ALIGN) -> [return: bb1, unwind continue];
25+
_4 = alloc::alloc::exchange_malloc(const <i32 as std::mem::SizedTypeProperties>::SIZE, const <i32 as std::mem::SizedTypeProperties>::ALIGNMENT) -> [return: bb1, unwind continue];
2626
}
2727

2828
bb1: {

0 commit comments

Comments
 (0)