Skip to content

Commit c3fe9e7

Browse files
committed
Auto merge of rust-lang#137078 - bjorn3:sync_cg_clif-2025-02-15, r=bjorn3
Subtree sync for rustc_codegen_cranelift This fixes a miscompilation (rust-lang/rustc_codegen_cranelift#1560) r? `@ghost` `@rustbot` label +A-codegen +A-cranelift +T-compiler
2 parents 500a686 + 7a6206e commit c3fe9e7

File tree

9 files changed

+20
-13
lines changed

9 files changed

+20
-13
lines changed

Diff for: compiler/rustc_codegen_cranelift/.github/workflows/main.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,8 @@ jobs:
188188
fail-fast: false
189189
matrix:
190190
include:
191-
# FIXME update at some point in the future once most distros use a newer glibc
192-
- os: ubuntu-20.04
191+
# Intentionally using an older ubuntu version to lower the glibc requirements of the distributed cg_clif
192+
- os: ubuntu-22.04
193193
env:
194194
TARGET_TRIPLE: x86_64-unknown-linux-gnu
195195
- os: macos-latest

Diff for: compiler/rustc_codegen_cranelift/rust-toolchain

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[toolchain]
2-
channel = "nightly-2025-02-07"
2+
channel = "nightly-2025-02-15"
33
components = ["rust-src", "rustc-dev", "llvm-tools"]
44
profile = "minimal"

Diff for: compiler/rustc_codegen_cranelift/rustfmt.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ ignore = [
33
]
44

55
# Matches rustfmt.toml of rustc
6-
version = "Two"
6+
style_edition = "2024"
77
use_small_heuristics = "Max"
88
merge_derives = false
99
group_imports = "StdExternalCrate"
1010
imports_granularity = "Module"
11+
use_field_init_shorthand = true

Diff for: compiler/rustc_codegen_cranelift/src/abi/pass_mode.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ pub(super) fn from_casted_value<'tcx>(
195195
// It may also be smaller for example when the type is a wrapper around an integer with a
196196
// larger alignment than the integer.
197197
std::cmp::max(abi_param_size, layout_size),
198-
u32::try_from(layout.align.pref.bytes()).unwrap(),
198+
u32::try_from(layout.align.abi.bytes()).unwrap(),
199199
);
200200
let mut offset = 0;
201201
let mut block_params_iter = block_params.iter().copied();

Diff for: compiler/rustc_codegen_cranelift/src/common.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,11 @@ impl<'tcx> FunctionCx<'_, '_, 'tcx> {
382382
}
383383

384384
pub(crate) fn create_stack_slot(&mut self, size: u32, align: u32) -> Pointer {
385+
assert!(
386+
size % align == 0,
387+
"size must be a multiple of alignment (size={size}, align={align})"
388+
);
389+
385390
let abi_align = if self.tcx.sess.target.arch == "s390x" { 8 } else { 16 };
386391
if align <= abi_align {
387392
let stack_slot = self.bcx.create_sized_stack_slot(StackSlotData {
@@ -403,7 +408,7 @@ impl<'tcx> FunctionCx<'_, '_, 'tcx> {
403408
align_shift: 4,
404409
});
405410
let base_ptr = self.bcx.ins().stack_addr(self.pointer_type, stack_slot, 0);
406-
let misalign_offset = self.bcx.ins().urem_imm(base_ptr, i64::from(align));
411+
let misalign_offset = self.bcx.ins().band_imm(base_ptr, i64::from(align - 1));
407412
let realign_offset = self.bcx.ins().irsub_imm(misalign_offset, i64::from(align));
408413
Pointer::new(self.bcx.ins().iadd(base_ptr, realign_offset))
409414
}

Diff for: compiler/rustc_codegen_cranelift/src/debuginfo/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ impl DebugContext {
304304
entry.set(gimli::DW_AT_decl_file, AttributeValue::FileIndex(Some(file_id)));
305305
entry.set(gimli::DW_AT_decl_line, AttributeValue::Udata(line));
306306

307-
entry.set(gimli::DW_AT_alignment, AttributeValue::Udata(static_layout.align.pref.bytes()));
307+
entry.set(gimli::DW_AT_alignment, AttributeValue::Udata(static_layout.align.abi.bytes()));
308308

309309
let mut expr = Expression::new();
310310
expr.op_addr(address_for_data(data_id));

Diff for: compiler/rustc_codegen_cranelift/src/debuginfo/types.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ impl DebugContext {
166166
let tuple_entry = self.dwarf.unit.get_mut(tuple_type_id);
167167
tuple_entry.set(gimli::DW_AT_name, AttributeValue::StringRef(self.dwarf.strings.add(name)));
168168
tuple_entry.set(gimli::DW_AT_byte_size, AttributeValue::Udata(layout.size.bytes()));
169-
tuple_entry.set(gimli::DW_AT_alignment, AttributeValue::Udata(layout.align.pref.bytes()));
169+
tuple_entry.set(gimli::DW_AT_alignment, AttributeValue::Udata(layout.align.abi.bytes()));
170170

171171
for (i, (ty, dw_ty)) in components.into_iter().enumerate() {
172172
let member_id = self.dwarf.unit.add(tuple_type_id, gimli::DW_TAG_member);
@@ -179,7 +179,7 @@ impl DebugContext {
179179
member_entry.set(
180180
gimli::DW_AT_alignment,
181181
AttributeValue::Udata(
182-
FullyMonomorphizedLayoutCx(tcx).layout_of(ty).align.pref.bytes(),
182+
FullyMonomorphizedLayoutCx(tcx).layout_of(ty).align.abi.bytes(),
183183
),
184184
);
185185
member_entry.set(

Diff for: compiler/rustc_codegen_cranelift/src/inline_asm.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,8 @@ fn call_inline_asm<'tcx>(
871871
inputs: Vec<(Size, Value)>,
872872
outputs: Vec<(Size, CPlace<'tcx>)>,
873873
) {
874-
let stack_slot = fx.create_stack_slot(u32::try_from(slot_size.bytes()).unwrap(), 16);
874+
let stack_slot =
875+
fx.create_stack_slot(u32::try_from(slot_size.bytes().next_multiple_of(16)).unwrap(), 16);
875876

876877
let inline_asm_func = fx
877878
.module

Diff for: compiler/rustc_codegen_cranelift/src/value_and_place.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ impl<'tcx> CValue<'tcx> {
101101
/// The is represented by a dangling pointer of suitable alignment.
102102
pub(crate) fn zst(layout: TyAndLayout<'tcx>) -> CValue<'tcx> {
103103
assert!(layout.is_zst());
104-
CValue::by_ref(crate::Pointer::dangling(layout.align.pref), layout)
104+
CValue::by_ref(crate::Pointer::dangling(layout.align.abi), layout)
105105
}
106106

107107
pub(crate) fn layout(&self) -> TyAndLayout<'tcx> {
@@ -392,7 +392,7 @@ impl<'tcx> CPlace<'tcx> {
392392
assert!(layout.is_sized());
393393
if layout.size.bytes() == 0 {
394394
return CPlace {
395-
inner: CPlaceInner::Addr(Pointer::dangling(layout.align.pref), None),
395+
inner: CPlaceInner::Addr(Pointer::dangling(layout.align.abi), None),
396396
layout,
397397
};
398398
}
@@ -405,7 +405,7 @@ impl<'tcx> CPlace<'tcx> {
405405

406406
let stack_slot = fx.create_stack_slot(
407407
u32::try_from(layout.size.bytes()).unwrap(),
408-
u32::try_from(layout.align.pref.bytes()).unwrap(),
408+
u32::try_from(layout.align.abi.bytes()).unwrap(),
409409
);
410410
CPlace { inner: CPlaceInner::Addr(stack_slot, None), layout }
411411
}

0 commit comments

Comments
 (0)