Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: unsized_locals: refuse to emit incorrect LLVM IR #71417

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions src/librustc_codegen_ssa/mir/operand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ impl<'a, 'tcx, V: CodegenObject> OperandValue<V> {
indirect_dest: PlaceRef<'tcx, V>,
) {
debug!("OperandRef::store_unsized: operand={:?}, indirect_dest={:?}", self, indirect_dest);
let flags = MemFlags::empty();
let _flags = MemFlags::empty();

// `indirect_dest` must have `*mut T` type. We extract `T` out of it.
let unsized_ty = indirect_dest
Expand All @@ -341,24 +341,27 @@ impl<'a, 'tcx, V: CodegenObject> OperandValue<V> {
.unwrap_or_else(|| bug!("indirect_dest has non-pointer type: {:?}", indirect_dest))
.ty;

let (llptr, llextra) = if let OperandValue::Ref(llptr, Some(llextra), _) = self {
let (_llptr, llextra) = if let OperandValue::Ref(llptr, Some(llextra), _) = self {
(llptr, llextra)
} else {
bug!("store_unsized called with a sized value")
};

// FIXME: choose an appropriate alignment, or use dynamic align somehow
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like back in #51131 someone noticed this, but wasn't aware that this is a soundness issue.

let max_align = Align::from_bits(128).unwrap();
let (_llsize, _llalign) = glue::size_and_align_of_dst(bx, unsized_ty, Some(llextra));

// FIXME: we have to use dynamic align somehow, but LLVM does not support that.
bug!("compiling unsized alloca is not supported by LLVM");
/*
let min_align = Align::from_bits(8).unwrap();

// Allocate an appropriate region on the stack, and copy the value into it
let (llsize, _) = glue::size_and_align_of_dst(bx, unsized_ty, Some(llextra));
let lldst = bx.array_alloca(bx.cx().type_i8(), llsize, max_align);
bx.memcpy(lldst, max_align, llptr, min_align, llsize, flags);
let lldst = bx.array_alloca(bx.cx().type_i8(), llsize, llalign);
bx.memcpy(lldst, llalign, llptr, min_align, llsize, flags);

// Store the allocated region and the extra to the indirect place.
let indirect_operand = OperandValue::Pair(lldst, llextra);
indirect_operand.store(bx, indirect_dest);
*/
}
}

Expand Down