Skip to content

Commit 49421d1

Browse files
committed
Remove support for dynamic allocas
1 parent 25cf7d1 commit 49421d1

File tree

9 files changed

+11
-86
lines changed

9 files changed

+11
-86
lines changed

compiler/rustc_codegen_gcc/src/builder.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -926,10 +926,6 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
926926
.get_address(self.location)
927927
}
928928

929-
fn dynamic_alloca(&mut self, _len: RValue<'gcc>, _align: Align) -> RValue<'gcc> {
930-
unimplemented!();
931-
}
932-
933929
fn load(&mut self, pointee_ty: Type<'gcc>, ptr: RValue<'gcc>, align: Align) -> RValue<'gcc> {
934930
let block = self.llbb();
935931
let function = block.get_function();

compiler/rustc_codegen_llvm/src/builder.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -538,16 +538,6 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
538538
}
539539
}
540540

541-
fn dynamic_alloca(&mut self, size: &'ll Value, align: Align) -> &'ll Value {
542-
unsafe {
543-
let alloca =
544-
llvm::LLVMBuildArrayAlloca(self.llbuilder, self.cx().type_i8(), size, UNNAMED);
545-
llvm::LLVMSetAlignment(alloca, align.bytes() as c_uint);
546-
// Cast to default addrspace if necessary
547-
llvm::LLVMBuildPointerCast(self.llbuilder, alloca, self.cx().type_ptr(), UNNAMED)
548-
}
549-
}
550-
551541
fn load(&mut self, ty: &'ll Type, ptr: &'ll Value, align: Align) -> &'ll Value {
552542
unsafe {
553543
let load = llvm::LLVMBuildLoad2(self.llbuilder, ty, ptr, UNNAMED);

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1492,12 +1492,6 @@ unsafe extern "C" {
14921492
Ty: &'a Type,
14931493
Name: *const c_char,
14941494
) -> &'a Value;
1495-
pub(crate) fn LLVMBuildArrayAlloca<'a>(
1496-
B: &Builder<'a>,
1497-
Ty: &'a Type,
1498-
Val: &'a Value,
1499-
Name: *const c_char,
1500-
) -> &'a Value;
15011495
pub(crate) fn LLVMBuildLoad2<'a>(
15021496
B: &Builder<'a>,
15031497
Ty: &'a Type,

compiler/rustc_codegen_ssa/src/mir/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ enum LocalRef<'tcx, V> {
140140
Place(PlaceRef<'tcx, V>),
141141
/// `UnsizedPlace(p)`: `p` itself is a thin pointer (indirect place).
142142
/// `*p` is the wide pointer that references the actual unsized place.
143-
/// Every time it is initialized, we have to reallocate the place
144-
/// and update the wide pointer. That's the reason why it is indirect.
143+
///
144+
/// Rust has no alloca and thus no ability to move the unsized place.
145145
UnsizedPlace(PlaceRef<'tcx, V>),
146146
/// The backend [`OperandValue`] has already been generated.
147147
Operand(OperandRef<'tcx, V>),
@@ -498,7 +498,7 @@ fn arg_local_refs<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
498498
LocalRef::Place(PlaceRef::new_sized(llarg, arg.layout))
499499
}
500500
}
501-
// Unsized indirect qrguments
501+
// Unsized indirect arguments
502502
PassMode::Indirect { attrs: _, meta_attrs: Some(_), on_stack: _ } => {
503503
// As the storage for the indirect argument lives during
504504
// the whole function call, we just copy the wide pointer.

compiler/rustc_codegen_ssa/src/mir/operand.rs

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ use tracing::{debug, instrument};
1616
use super::place::{PlaceRef, PlaceValue};
1717
use super::rvalue::transmute_scalar;
1818
use super::{FunctionCx, LocalRef};
19+
use crate::MemFlags;
1920
use crate::common::IntPredicate;
2021
use crate::traits::*;
21-
use crate::{MemFlags, size_of_val};
2222

2323
/// The representation of a Rust value. The enum variant is in fact
2424
/// uniquely determined by the value's type, but is kept as a
@@ -800,44 +800,6 @@ impl<'a, 'tcx, V: CodegenObject> OperandValue<V> {
800800
}
801801
}
802802
}
803-
804-
pub fn store_unsized<Bx: BuilderMethods<'a, 'tcx, Value = V>>(
805-
self,
806-
bx: &mut Bx,
807-
indirect_dest: PlaceRef<'tcx, V>,
808-
) {
809-
debug!("OperandRef::store_unsized: operand={:?}, indirect_dest={:?}", self, indirect_dest);
810-
// `indirect_dest` must have `*mut T` type. We extract `T` out of it.
811-
let unsized_ty = indirect_dest
812-
.layout
813-
.ty
814-
.builtin_deref(true)
815-
.unwrap_or_else(|| bug!("indirect_dest has non-pointer type: {:?}", indirect_dest));
816-
817-
let OperandValue::Ref(PlaceValue { llval: llptr, llextra: Some(llextra), .. }) = self
818-
else {
819-
bug!("store_unsized called with a sized value (or with an extern type)")
820-
};
821-
822-
// Allocate an appropriate region on the stack, and copy the value into it. Since alloca
823-
// doesn't support dynamic alignment, we allocate an extra align - 1 bytes, and align the
824-
// pointer manually.
825-
let (size, align) = size_of_val::size_and_align_of_dst(bx, unsized_ty, Some(llextra));
826-
let one = bx.const_usize(1);
827-
let align_minus_1 = bx.sub(align, one);
828-
let size_extra = bx.add(size, align_minus_1);
829-
let min_align = Align::ONE;
830-
let alloca = bx.dynamic_alloca(size_extra, min_align);
831-
let address = bx.ptrtoint(alloca, bx.type_isize());
832-
let neg_address = bx.neg(address);
833-
let offset = bx.and(neg_address, align_minus_1);
834-
let dst = bx.inbounds_ptradd(alloca, offset);
835-
bx.memcpy(dst, min_align, llptr, min_align, size, MemFlags::empty());
836-
837-
// Store the allocated region and the extra to the indirect place.
838-
let indirect_operand = OperandValue::Pair(dst, llextra);
839-
indirect_operand.store(bx, indirect_dest);
840-
}
841803
}
842804

843805
impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {

compiler/rustc_codegen_ssa/src/mir/rvalue.rs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -328,27 +328,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
328328
Some(imm)
329329
}
330330

331-
pub(crate) fn codegen_rvalue_unsized(
332-
&mut self,
333-
bx: &mut Bx,
334-
indirect_dest: PlaceRef<'tcx, Bx::Value>,
335-
rvalue: &mir::Rvalue<'tcx>,
336-
) {
337-
debug!(
338-
"codegen_rvalue_unsized(indirect_dest.llval={:?}, rvalue={:?})",
339-
indirect_dest.val.llval, rvalue
340-
);
341-
342-
match *rvalue {
343-
mir::Rvalue::Use(ref operand) => {
344-
let cg_operand = self.codegen_operand(bx, operand);
345-
cg_operand.val.store_unsized(bx, indirect_dest);
346-
}
347-
348-
_ => bug!("unsized assignment other than `Rvalue::Use`"),
349-
}
350-
}
351-
352331
pub(crate) fn codegen_rvalue_operand(
353332
&mut self,
354333
bx: &mut Bx,

compiler/rustc_codegen_ssa/src/mir/statement.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
1515
match self.locals[index] {
1616
LocalRef::Place(cg_dest) => self.codegen_rvalue(bx, cg_dest, rvalue),
1717
LocalRef::UnsizedPlace(cg_indirect_dest) => {
18-
self.codegen_rvalue_unsized(bx, cg_indirect_dest, rvalue)
18+
let ty = cg_indirect_dest.layout.ty;
19+
span_bug!(
20+
statement.source_info.span,
21+
"cannot reallocate from `UnsizedPlace({ty})` \
22+
into `{rvalue:?}`; dynamic alloca is not supported",
23+
);
1924
}
2025
LocalRef::PendingOperand => {
2126
let operand = self.codegen_rvalue_operand(bx, rvalue);

compiler/rustc_codegen_ssa/src/traits/builder.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,6 @@ pub trait BuilderMethods<'a, 'tcx>:
224224
fn to_immediate_scalar(&mut self, val: Self::Value, scalar: Scalar) -> Self::Value;
225225

226226
fn alloca(&mut self, size: Size, align: Align) -> Self::Value;
227-
fn dynamic_alloca(&mut self, size: Self::Value, align: Align) -> Self::Value;
228227

229228
fn load(&mut self, ty: Self::Type, ptr: Self::Value, align: Align) -> Self::Value;
230229
fn volatile_load(&mut self, ty: Self::Type, ptr: Self::Value) -> Self::Value;

library/core/src/mem/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ pub const fn forget<T>(t: T) {
151151
///
152152
/// While Rust does not permit unsized locals since its removal in [#111942] it is
153153
/// still possible to call functions with unsized values from a function argument
154-
/// or in-place construction.
154+
/// or place expression.
155155
///
156156
/// ```rust
157157
/// #![feature(unsized_fn_params, forget_unsized)]

0 commit comments

Comments
 (0)