Skip to content

Commit 085c9e6

Browse files
authored
Rollup merge of rust-lang#64003 - Dante-Broggi:place-align-in-layout, r=matthewjasper
place: Passing `align` = `layout.align.abi`, when also passing `layout` Of the calls changed: 7/12 use `align` = `layout.align.abi`. `from_const_alloc` uses `alloc.align`, but that is `assert_eq!` to `layout.align.abi`. only 4/11 use something interesting for `align`.
2 parents d855bde + 8657fb1 commit 085c9e6

File tree

8 files changed

+25
-14
lines changed

8 files changed

+25
-14
lines changed

src/librustc_codegen_llvm/builder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
561561

562562
let align = dest.align.restrict_for_offset(dest.layout.field(self.cx(), 0).size);
563563
cg_elem.val.store(&mut body_bx,
564-
PlaceRef::new_sized(current, cg_elem.layout, align));
564+
PlaceRef::new_sized_aligned(current, cg_elem.layout, align));
565565

566566
let next = body_bx.inbounds_gep(current, &[self.const_usize(1)]);
567567
body_bx.br(header_bx.llbb());

src/librustc_codegen_llvm/common.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ impl ConstMethods<'tcx> for CodegenCx<'ll, 'tcx> {
349349
)};
350350
self.const_bitcast(llval, llty)
351351
};
352-
PlaceRef::new_sized(llval, layout, alloc.align)
352+
PlaceRef::new_sized(llval, layout)
353353
}
354354

355355
fn const_ptrcast(&self, val: &'ll Value, ty: &'ll Type) -> &'ll Value {

src/librustc_codegen_llvm/intrinsic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ impl IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
101101
let name = &*tcx.item_name(def_id).as_str();
102102

103103
let llret_ty = self.layout_of(ret_ty).llvm_type(self);
104-
let result = PlaceRef::new_sized(llresult, fn_ty.ret.layout, fn_ty.ret.layout.align.abi);
104+
let result = PlaceRef::new_sized(llresult, fn_ty.ret.layout);
105105

106106
let simple = get_simple_intrinsic(self, name);
107107
let llval = match name {

src/librustc_codegen_ssa/mir/block.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -988,7 +988,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
988988

989989
// Handle both by-ref and immediate tuples.
990990
if let Ref(llval, None, align) = tuple.val {
991-
let tuple_ptr = PlaceRef::new_sized(llval, tuple.layout, align);
991+
let tuple_ptr = PlaceRef::new_sized_aligned(llval, tuple.layout, align);
992992
for i in 0..tuple.layout.fields.count() {
993993
let field_ptr = tuple_ptr.project_field(bx, i);
994994
let field = bx.load_operand(field_ptr);
@@ -1202,7 +1202,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
12021202
let llty = bx.backend_type(src.layout);
12031203
let cast_ptr = bx.pointercast(dst.llval, bx.type_ptr_to(llty));
12041204
let align = src.layout.align.abi.min(dst.align);
1205-
src.val.store(bx, PlaceRef::new_sized(cast_ptr, src.layout, align));
1205+
src.val.store(bx, PlaceRef::new_sized_aligned(cast_ptr, src.layout, align));
12061206
}
12071207

12081208

src/librustc_codegen_ssa/mir/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
289289
if local == mir::RETURN_PLACE && fx.fn_ty.ret.is_indirect() {
290290
debug!("alloc: {:?} (return place) -> place", local);
291291
let llretptr = bx.get_param(0);
292-
LocalRef::Place(PlaceRef::new_sized(llretptr, layout, layout.align.abi))
292+
LocalRef::Place(PlaceRef::new_sized(llretptr, layout))
293293
} else if memory_locals.contains(local) {
294294
debug!("alloc: {:?} -> place", local);
295295
if layout.is_unsized() {
@@ -548,7 +548,7 @@ fn arg_local_refs<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
548548
let llarg = bx.get_param(llarg_idx);
549549
bx.set_value_name(llarg, &name);
550550
llarg_idx += 1;
551-
PlaceRef::new_sized(llarg, arg.layout, arg.layout.align.abi)
551+
PlaceRef::new_sized(llarg, arg.layout)
552552
} else if arg.is_unsized_indirect() {
553553
// As the storage for the indirect argument lives during
554554
// the whole function call, we just copy the fat pointer.

src/librustc_codegen_ssa/mir/operand.rs

-1
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
485485
bx.load_operand(PlaceRef::new_sized(
486486
bx.cx().const_undef(bx.cx().type_ptr_to(bx.cx().backend_type(layout))),
487487
layout,
488-
layout.align.abi,
489488
))
490489
})
491490
}

src/librustc_codegen_ssa/mir/place.rs

+17-5
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,19 @@ impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> {
3030
pub fn new_sized(
3131
llval: V,
3232
layout: TyLayout<'tcx>,
33+
) -> PlaceRef<'tcx, V> {
34+
assert!(!layout.is_unsized());
35+
PlaceRef {
36+
llval,
37+
llextra: None,
38+
layout,
39+
align: layout.align.abi
40+
}
41+
}
42+
43+
pub fn new_sized_aligned(
44+
llval: V,
45+
layout: TyLayout<'tcx>,
3346
align: Align,
3447
) -> PlaceRef<'tcx, V> {
3548
assert!(!layout.is_unsized());
@@ -45,14 +58,13 @@ impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> {
4558
bx: &mut Bx,
4659
llval: V,
4760
layout: TyLayout<'tcx>,
48-
align: Align,
4961
) -> PlaceRef<'tcx, V> {
5062
assert!(!bx.cx().type_has_metadata(layout.ty));
5163
PlaceRef {
5264
llval,
5365
llextra: None,
5466
layout,
55-
align
67+
align: layout.align.abi
5668
}
5769
}
5870

@@ -64,7 +76,7 @@ impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> {
6476
debug!("alloca({:?}: {:?})", name, layout);
6577
assert!(!layout.is_unsized(), "tried to statically allocate unsized place");
6678
let tmp = bx.alloca(bx.cx().backend_type(layout), name, layout.align.abi);
67-
Self::new_sized(tmp, layout, layout.align.abi)
79+
Self::new_sized(tmp, layout)
6880
}
6981

7082
/// Returns a place for an indirect reference to an unsized place.
@@ -482,7 +494,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
482494
let llval = bx.cx().const_undef(
483495
bx.cx().type_ptr_to(bx.cx().backend_type(layout))
484496
);
485-
PlaceRef::new_sized(llval, layout, layout.align.abi)
497+
PlaceRef::new_sized(llval, layout)
486498
}
487499
}
488500
}
@@ -498,7 +510,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
498510
// with a static that is an extern_type.
499511
let layout = cx.layout_of(self.monomorphize(&ty));
500512
let static_ = bx.get_static(*def_id);
501-
PlaceRef::new_thin_place(bx, static_, layout, layout.align.abi)
513+
PlaceRef::new_thin_place(bx, static_, layout)
502514
},
503515
mir::PlaceRef {
504516
base,

src/librustc_codegen_ssa/mir/rvalue.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
7171
scratch.storage_dead(&mut bx);
7272
}
7373
OperandValue::Ref(llref, None, align) => {
74-
let source = PlaceRef::new_sized(llref, operand.layout, align);
74+
let source = PlaceRef::new_sized_aligned(llref, operand.layout, align);
7575
base::coerce_unsized_into(&mut bx, source, dest);
7676
}
7777
OperandValue::Ref(_, Some(_), _) => {

0 commit comments

Comments
 (0)