Skip to content

Commit 13180c2

Browse files
committed
Remove support for dynamic allocas
1 parent 8051f01 commit 13180c2

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
@@ -931,10 +931,6 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
931931
.get_address(self.location)
932932
}
933933

934-
fn dynamic_alloca(&mut self, _len: RValue<'gcc>, _align: Align) -> RValue<'gcc> {
935-
unimplemented!();
936-
}
937-
938934
fn load(&mut self, pointee_ty: Type<'gcc>, ptr: RValue<'gcc>, align: Align) -> RValue<'gcc> {
939935
let block = self.llbb();
940936
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
@@ -15,9 +15,9 @@ use tracing::{debug, instrument};
1515
use super::place::{PlaceRef, PlaceValue};
1616
use super::rvalue::transmute_immediate;
1717
use super::{FunctionCx, LocalRef};
18+
use crate::MemFlags;
1819
use crate::common::IntPredicate;
1920
use crate::traits::*;
20-
use crate::{MemFlags, size_of_val};
2121

2222
/// The representation of a Rust value. The enum variant is in fact
2323
/// uniquely determined by the value's type, but is kept as a
@@ -771,44 +771,6 @@ impl<'a, 'tcx, V: CodegenObject> OperandValue<V> {
771771
}
772772
}
773773
}
774-
775-
pub fn store_unsized<Bx: BuilderMethods<'a, 'tcx, Value = V>>(
776-
self,
777-
bx: &mut Bx,
778-
indirect_dest: PlaceRef<'tcx, V>,
779-
) {
780-
debug!("OperandRef::store_unsized: operand={:?}, indirect_dest={:?}", self, indirect_dest);
781-
// `indirect_dest` must have `*mut T` type. We extract `T` out of it.
782-
let unsized_ty = indirect_dest
783-
.layout
784-
.ty
785-
.builtin_deref(true)
786-
.unwrap_or_else(|| bug!("indirect_dest has non-pointer type: {:?}", indirect_dest));
787-
788-
let OperandValue::Ref(PlaceValue { llval: llptr, llextra: Some(llextra), .. }) = self
789-
else {
790-
bug!("store_unsized called with a sized value (or with an extern type)")
791-
};
792-
793-
// Allocate an appropriate region on the stack, and copy the value into it. Since alloca
794-
// doesn't support dynamic alignment, we allocate an extra align - 1 bytes, and align the
795-
// pointer manually.
796-
let (size, align) = size_of_val::size_and_align_of_dst(bx, unsized_ty, Some(llextra));
797-
let one = bx.const_usize(1);
798-
let align_minus_1 = bx.sub(align, one);
799-
let size_extra = bx.add(size, align_minus_1);
800-
let min_align = Align::ONE;
801-
let alloca = bx.dynamic_alloca(size_extra, min_align);
802-
let address = bx.ptrtoint(alloca, bx.type_isize());
803-
let neg_address = bx.neg(address);
804-
let offset = bx.and(neg_address, align_minus_1);
805-
let dst = bx.inbounds_ptradd(alloca, offset);
806-
bx.memcpy(dst, min_align, llptr, min_align, size, MemFlags::empty());
807-
808-
// Store the allocated region and the extra to the indirect place.
809-
let indirect_operand = OperandValue::Pair(dst, llextra);
810-
indirect_operand.store(bx, indirect_dest);
811-
}
812774
}
813775

814776
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
@@ -364,27 +364,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
364364
Some(imm)
365365
}
366366

367-
pub(crate) fn codegen_rvalue_unsized(
368-
&mut self,
369-
bx: &mut Bx,
370-
indirect_dest: PlaceRef<'tcx, Bx::Value>,
371-
rvalue: &mir::Rvalue<'tcx>,
372-
) {
373-
debug!(
374-
"codegen_rvalue_unsized(indirect_dest.llval={:?}, rvalue={:?})",
375-
indirect_dest.val.llval, rvalue
376-
);
377-
378-
match *rvalue {
379-
mir::Rvalue::Use(ref operand) => {
380-
let cg_operand = self.codegen_operand(bx, operand);
381-
cg_operand.val.store_unsized(bx, indirect_dest);
382-
}
383-
384-
_ => bug!("unsized assignment other than `Rvalue::Use`"),
385-
}
386-
}
387-
388367
pub(crate) fn codegen_rvalue_operand(
389368
&mut self,
390369
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)