about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbjorn3 <17426603+bjorn3@users.noreply.github.com>2025-02-13 14:22:57 +0000
committerbjorn3 <17426603+bjorn3@users.noreply.github.com>2025-02-13 14:22:57 +0000
commitc27715bf66353eb77625eec2f9ebcf4bda68497d (patch)
tree7b0de2e52ec3b0d794f0ccf22237706836babee2
parentecad6893321362e75b249f49648835b5a8e7371d (diff)
downloadrust-c27715bf66353eb77625eec2f9ebcf4bda68497d.tar.gz
rust-c27715bf66353eb77625eec2f9ebcf4bda68497d.zip
Use abi rather than preferred alignment everywhere
Turns out the size of a type is not necessarily a multiple of the
preferred alignment, which broke the realignment logic in
create_stack_slot.
-rw-r--r--src/abi/pass_mode.rs2
-rw-r--r--src/common.rs5
-rw-r--r--src/debuginfo/mod.rs2
-rw-r--r--src/debuginfo/types.rs4
-rw-r--r--src/value_and_place.rs6
5 files changed, 12 insertions, 7 deletions
diff --git a/src/abi/pass_mode.rs b/src/abi/pass_mode.rs
index 7594a53fc75..b28c4c9539c 100644
--- a/src/abi/pass_mode.rs
+++ b/src/abi/pass_mode.rs
@@ -195,7 +195,7 @@ pub(super) fn from_casted_value<'tcx>(
         // It may also be smaller for example when the type is a wrapper around an integer with a
         // larger alignment than the integer.
         std::cmp::max(abi_param_size, layout_size),
-        u32::try_from(layout.align.pref.bytes()).unwrap(),
+        u32::try_from(layout.align.abi.bytes()).unwrap(),
     );
     let mut offset = 0;
     let mut block_params_iter = block_params.iter().copied();
diff --git a/src/common.rs b/src/common.rs
index 534557fcd41..25941e07a19 100644
--- a/src/common.rs
+++ b/src/common.rs
@@ -382,6 +382,11 @@ impl<'tcx> FunctionCx<'_, '_, 'tcx> {
     }
 
     pub(crate) fn create_stack_slot(&mut self, size: u32, align: u32) -> Pointer {
+        assert!(
+            size % align == 0,
+            "size must be a multiple of alignment (size={size}, align={align})"
+        );
+
         let abi_align = if self.tcx.sess.target.arch == "s390x" { 8 } else { 16 };
         if align <= abi_align {
             let stack_slot = self.bcx.create_sized_stack_slot(StackSlotData {
diff --git a/src/debuginfo/mod.rs b/src/debuginfo/mod.rs
index f3a8623e216..bba6567774d 100644
--- a/src/debuginfo/mod.rs
+++ b/src/debuginfo/mod.rs
@@ -304,7 +304,7 @@ impl DebugContext {
         entry.set(gimli::DW_AT_decl_file, AttributeValue::FileIndex(Some(file_id)));
         entry.set(gimli::DW_AT_decl_line, AttributeValue::Udata(line));
 
-        entry.set(gimli::DW_AT_alignment, AttributeValue::Udata(static_layout.align.pref.bytes()));
+        entry.set(gimli::DW_AT_alignment, AttributeValue::Udata(static_layout.align.abi.bytes()));
 
         let mut expr = Expression::new();
         expr.op_addr(address_for_data(data_id));
diff --git a/src/debuginfo/types.rs b/src/debuginfo/types.rs
index a2f6691cdd2..017d7784dc0 100644
--- a/src/debuginfo/types.rs
+++ b/src/debuginfo/types.rs
@@ -166,7 +166,7 @@ impl DebugContext {
         let tuple_entry = self.dwarf.unit.get_mut(tuple_type_id);
         tuple_entry.set(gimli::DW_AT_name, AttributeValue::StringRef(self.dwarf.strings.add(name)));
         tuple_entry.set(gimli::DW_AT_byte_size, AttributeValue::Udata(layout.size.bytes()));
-        tuple_entry.set(gimli::DW_AT_alignment, AttributeValue::Udata(layout.align.pref.bytes()));
+        tuple_entry.set(gimli::DW_AT_alignment, AttributeValue::Udata(layout.align.abi.bytes()));
 
         for (i, (ty, dw_ty)) in components.into_iter().enumerate() {
             let member_id = self.dwarf.unit.add(tuple_type_id, gimli::DW_TAG_member);
@@ -179,7 +179,7 @@ impl DebugContext {
             member_entry.set(
                 gimli::DW_AT_alignment,
                 AttributeValue::Udata(
-                    FullyMonomorphizedLayoutCx(tcx).layout_of(ty).align.pref.bytes(),
+                    FullyMonomorphizedLayoutCx(tcx).layout_of(ty).align.abi.bytes(),
                 ),
             );
             member_entry.set(
diff --git a/src/value_and_place.rs b/src/value_and_place.rs
index c17d1f30fbe..a9b8e1bd393 100644
--- a/src/value_and_place.rs
+++ b/src/value_and_place.rs
@@ -101,7 +101,7 @@ impl<'tcx> CValue<'tcx> {
     /// The is represented by a dangling pointer of suitable alignment.
     pub(crate) fn zst(layout: TyAndLayout<'tcx>) -> CValue<'tcx> {
         assert!(layout.is_zst());
-        CValue::by_ref(crate::Pointer::dangling(layout.align.pref), layout)
+        CValue::by_ref(crate::Pointer::dangling(layout.align.abi), layout)
     }
 
     pub(crate) fn layout(&self) -> TyAndLayout<'tcx> {
@@ -392,7 +392,7 @@ impl<'tcx> CPlace<'tcx> {
         assert!(layout.is_sized());
         if layout.size.bytes() == 0 {
             return CPlace {
-                inner: CPlaceInner::Addr(Pointer::dangling(layout.align.pref), None),
+                inner: CPlaceInner::Addr(Pointer::dangling(layout.align.abi), None),
                 layout,
             };
         }
@@ -405,7 +405,7 @@ impl<'tcx> CPlace<'tcx> {
 
         let stack_slot = fx.create_stack_slot(
             u32::try_from(layout.size.bytes()).unwrap(),
-            u32::try_from(layout.align.pref.bytes()).unwrap(),
+            u32::try_from(layout.align.abi.bytes()).unwrap(),
         );
         CPlace { inner: CPlaceInner::Addr(stack_slot, None), layout }
     }