Skip to content

Commit 8657fb1

Browse files
committed
new_sized is mostly used without align
so rename it `new_sized_aligned`. 6/11 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`.
1 parent 0cc1c8d commit 8657fb1

File tree

8 files changed

+23
-11
lines changed

8 files changed

+23
-11
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
@@ -348,7 +348,7 @@ impl ConstMethods<'tcx> for CodegenCx<'ll, 'tcx> {
348348
)};
349349
self.const_bitcast(llval, llty)
350350
};
351-
PlaceRef::new_sized(llval, layout, alloc.align)
351+
PlaceRef::new_sized(llval, layout)
352352
}
353353

354354
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
@@ -989,7 +989,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
989989

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

12091209

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

+15-2
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());
@@ -63,7 +76,7 @@ impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> {
6376
debug!("alloca({:?}: {:?})", name, layout);
6477
assert!(!layout.is_unsized(), "tried to statically allocate unsized place");
6578
let tmp = bx.alloca(bx.cx().backend_type(layout), name, layout.align.abi);
66-
Self::new_sized(tmp, layout, layout.align.abi)
79+
Self::new_sized(tmp, layout)
6780
}
6881

6982
/// Returns a place for an indirect reference to an unsized place.
@@ -481,7 +494,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
481494
let llval = bx.cx().const_undef(
482495
bx.cx().type_ptr_to(bx.cx().backend_type(layout))
483496
);
484-
PlaceRef::new_sized(llval, layout, layout.align.abi)
497+
PlaceRef::new_sized(llval, layout)
485498
}
486499
}
487500
}

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)