Auto merge of #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 #121577. r? `@ghost`
This commit is contained in:
commit
752af44fc4
@ -898,26 +898,20 @@ fn checked_binop(
|
|||||||
self.gcc_checked_binop(oop, typ, lhs, rhs)
|
self.gcc_checked_binop(oop, typ, lhs, rhs)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn alloca(&mut self, ty: Type<'gcc>, align: Align) -> RValue<'gcc> {
|
fn alloca(&mut self, size: Size, align: Align) -> RValue<'gcc> {
|
||||||
// FIXME(antoyo): this check that we don't call get_aligned() a second time on a type.
|
let ty = self.cx.type_array(self.cx.type_i8(), size.bytes()).get_aligned(align.bytes());
|
||||||
// Ideally, we shouldn't need to do this check.
|
|
||||||
let aligned_type = if ty == self.cx.u128_type || ty == self.cx.i128_type {
|
|
||||||
ty
|
|
||||||
} else {
|
|
||||||
ty.get_aligned(align.bytes())
|
|
||||||
};
|
|
||||||
// TODO(antoyo): It might be better to return a LValue, but fixing the rustc API is non-trivial.
|
// TODO(antoyo): It might be better to return a LValue, but fixing the rustc API is non-trivial.
|
||||||
self.stack_var_count.set(self.stack_var_count.get() + 1);
|
self.stack_var_count.set(self.stack_var_count.get() + 1);
|
||||||
self.current_func()
|
self.current_func()
|
||||||
.new_local(
|
.new_local(
|
||||||
self.location,
|
self.location,
|
||||||
aligned_type,
|
ty,
|
||||||
&format!("stack_var_{}", self.stack_var_count.get()),
|
&format!("stack_var_{}", self.stack_var_count.get()),
|
||||||
)
|
)
|
||||||
.get_address(self.location)
|
.get_address(self.location)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn byte_array_alloca(&mut self, _len: RValue<'gcc>, _align: Align) -> RValue<'gcc> {
|
fn dynamic_alloca(&mut self, _len: RValue<'gcc>, _align: Align) -> RValue<'gcc> {
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -531,7 +531,7 @@ fn store(
|
|||||||
// We instead thus allocate some scratch space...
|
// We instead thus allocate some scratch space...
|
||||||
let scratch_size = cast.size(bx);
|
let scratch_size = cast.size(bx);
|
||||||
let scratch_align = cast.align(bx);
|
let scratch_align = cast.align(bx);
|
||||||
let llscratch = bx.alloca(cast.gcc_type(bx), scratch_align);
|
let llscratch = bx.alloca(scratch_size, scratch_align);
|
||||||
bx.lifetime_start(llscratch, scratch_size);
|
bx.lifetime_start(llscratch, scratch_size);
|
||||||
|
|
||||||
// ... where we first store the value...
|
// ... where we first store the value...
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
use rustc_middle::ty::layout::HasTyCtxt;
|
use rustc_middle::ty::layout::HasTyCtxt;
|
||||||
use rustc_middle::ty::{self, Ty};
|
use rustc_middle::ty::{self, Ty};
|
||||||
use rustc_span::{sym, Span, Symbol};
|
use rustc_span::{sym, Span, Symbol};
|
||||||
use rustc_target::abi::Align;
|
use rustc_target::abi::{Align, Size};
|
||||||
|
|
||||||
use crate::builder::Builder;
|
use crate::builder::Builder;
|
||||||
#[cfg(not(feature = "master"))]
|
#[cfg(not(feature = "master"))]
|
||||||
@ -558,7 +558,7 @@ macro_rules! arith_binary {
|
|||||||
let ze = bx.zext(result, bx.type_ix(expected_bytes * 8));
|
let ze = bx.zext(result, bx.type_ix(expected_bytes * 8));
|
||||||
|
|
||||||
// Convert the integer to a byte array
|
// Convert the integer to a byte array
|
||||||
let ptr = bx.alloca(bx.type_ix(expected_bytes * 8), Align::ONE);
|
let ptr = bx.alloca(Size::from_bytes(expected_bytes), Align::ONE);
|
||||||
bx.store(ze, ptr, Align::ONE);
|
bx.store(ze, ptr, Align::ONE);
|
||||||
let array_ty = bx.type_array(bx.type_i8(), expected_bytes);
|
let array_ty = bx.type_array(bx.type_i8(), expected_bytes);
|
||||||
let ptr = bx.pointercast(ptr, bx.cx.type_ptr_to(array_ty));
|
let ptr = bx.pointercast(ptr, bx.cx.type_ptr_to(array_ty));
|
||||||
|
Loading…
Reference in New Issue
Block a user