Skip to content

Commit 752af44

Browse files
committed
Auto merge of rust-lang#122053 - erikdesjardins:alloca, r=nikic
Stop using LLVM struct types for alloca The alloca type has no semantic meaning, only the size (and alignment, but we specify it explicitly) matter. Using `[N x i8]` is a more direct way to specify that we want `N` bytes, and avoids relying on LLVM's struct layout. It is likely that a future LLVM version will change to an untyped alloca representation. Split out from rust-lang#121577. r? `@ghost`
2 parents 79d217f + 50a1471 commit 752af44

File tree

3 files changed

+7
-13
lines changed

3 files changed

+7
-13
lines changed

src/builder.rs

+4-10
Original file line numberDiff line numberDiff line change
@@ -898,26 +898,20 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
898898
self.gcc_checked_binop(oop, typ, lhs, rhs)
899899
}
900900

901-
fn alloca(&mut self, ty: Type<'gcc>, align: Align) -> RValue<'gcc> {
902-
// FIXME(antoyo): this check that we don't call get_aligned() a second time on a type.
903-
// Ideally, we shouldn't need to do this check.
904-
let aligned_type = if ty == self.cx.u128_type || ty == self.cx.i128_type {
905-
ty
906-
} else {
907-
ty.get_aligned(align.bytes())
908-
};
901+
fn alloca(&mut self, size: Size, align: Align) -> RValue<'gcc> {
902+
let ty = self.cx.type_array(self.cx.type_i8(), size.bytes()).get_aligned(align.bytes());
909903
// TODO(antoyo): It might be better to return a LValue, but fixing the rustc API is non-trivial.
910904
self.stack_var_count.set(self.stack_var_count.get() + 1);
911905
self.current_func()
912906
.new_local(
913907
self.location,
914-
aligned_type,
908+
ty,
915909
&format!("stack_var_{}", self.stack_var_count.get()),
916910
)
917911
.get_address(self.location)
918912
}
919913

920-
fn byte_array_alloca(&mut self, _len: RValue<'gcc>, _align: Align) -> RValue<'gcc> {
914+
fn dynamic_alloca(&mut self, _len: RValue<'gcc>, _align: Align) -> RValue<'gcc> {
921915
unimplemented!();
922916
}
923917

src/intrinsic/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ impl<'gcc, 'tcx> ArgAbiExt<'gcc, 'tcx> for ArgAbi<'tcx, Ty<'tcx>> {
531531
// We instead thus allocate some scratch space...
532532
let scratch_size = cast.size(bx);
533533
let scratch_align = cast.align(bx);
534-
let llscratch = bx.alloca(cast.gcc_type(bx), scratch_align);
534+
let llscratch = bx.alloca(scratch_size, scratch_align);
535535
bx.lifetime_start(llscratch, scratch_size);
536536

537537
// ... where we first store the value...

src/intrinsic/simd.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use rustc_middle::span_bug;
1818
use rustc_middle::ty::layout::HasTyCtxt;
1919
use rustc_middle::ty::{self, Ty};
2020
use rustc_span::{sym, Span, Symbol};
21-
use rustc_target::abi::Align;
21+
use rustc_target::abi::{Align, Size};
2222

2323
use crate::builder::Builder;
2424
#[cfg(not(feature = "master"))]
@@ -558,7 +558,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
558558
let ze = bx.zext(result, bx.type_ix(expected_bytes * 8));
559559

560560
// Convert the integer to a byte array
561-
let ptr = bx.alloca(bx.type_ix(expected_bytes * 8), Align::ONE);
561+
let ptr = bx.alloca(Size::from_bytes(expected_bytes), Align::ONE);
562562
bx.store(ze, ptr, Align::ONE);
563563
let array_ty = bx.type_array(bx.type_i8(), expected_bytes);
564564
let ptr = bx.pointercast(ptr, bx.cx.type_ptr_to(array_ty));

0 commit comments

Comments
 (0)