Skip to content

Commit a0edba0

Browse files
authored
Unrolled build for rust-lang#118551
Rollup merge of rust-lang#118551 - RalfJung:extern-types-bugs, r=compiler-errors more targeted errors when extern types end up in places they should not Cc rust-lang#115709 -- this does not fix that bug but it makes the panics less obscure and makes it more clear that this is a deeper issue than just a little codegen oversight. (In rust-lang#116115 we decided we'd stick to causing ICEs here for now, rather than nicer errors. We can't currently show any errors pre-mono and probably we don't want post-mono checks when this gets stabilized anyway.)
2 parents 0a83e43 + 5a20bac commit a0edba0

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

compiler/rustc_codegen_llvm/src/builder.rs

+9
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,15 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
489489

490490
#[instrument(level = "trace", skip(self))]
491491
fn load_operand(&mut self, place: PlaceRef<'tcx, &'ll Value>) -> OperandRef<'tcx, &'ll Value> {
492+
if place.layout.is_unsized() {
493+
let tail = self.tcx.struct_tail_with_normalize(place.layout.ty, |ty| ty, || {});
494+
if matches!(tail.kind(), ty::Foreign(..)) {
495+
// Unsized locals and, at least conceptually, even unsized arguments must be copied
496+
// around, which requires dynamically determining their size. Therefore, we cannot
497+
// allow `extern` types here. Consult t-opsem before removing this check.
498+
panic!("unsized locals must not be `extern` types");
499+
}
500+
}
492501
assert_eq!(place.llextra.is_some(), place.layout.is_unsized());
493502

494503
if place.layout.is_zst() {

compiler/rustc_codegen_ssa/src/mir/operand.rs

+1
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@ impl<'a, 'tcx, V: CodegenObject> OperandValue<V> {
414414
// value is through `undef`/`poison`, and the store itself is useless.
415415
}
416416
OperandValue::Ref(r, None, source_align) => {
417+
assert!(dest.layout.is_sized(), "cannot directly store unsized values");
417418
if flags.contains(MemFlags::NONTEMPORAL) {
418419
// HACK(nox): This is inefficient but there is no nontemporal memcpy.
419420
let ty = bx.backend_type(dest.layout);

compiler/rustc_ty_utils/src/abi.rs

+12
Original file line numberDiff line numberDiff line change
@@ -424,11 +424,23 @@ fn fn_abi_sanity_check<'tcx>(
424424
}
425425
PassMode::Indirect { meta_attrs: None, .. } => {
426426
// No metadata, must be sized.
427+
// Conceptually, unsized arguments must be copied around, which requires dynamically
428+
// determining their size, which we cannot do without metadata. Consult
429+
// t-opsem before removing this check.
427430
assert!(arg.layout.is_sized());
428431
}
429432
PassMode::Indirect { meta_attrs: Some(_), on_stack, .. } => {
430433
// With metadata. Must be unsized and not on the stack.
431434
assert!(arg.layout.is_unsized() && !on_stack);
435+
// Also, must not be `extern` type.
436+
let tail = cx.tcx.struct_tail_with_normalize(arg.layout.ty, |ty| ty, || {});
437+
if matches!(tail.kind(), ty::Foreign(..)) {
438+
// These types do not have metadata, so having `meta_attrs` is bogus.
439+
// Conceptually, unsized arguments must be copied around, which requires dynamically
440+
// determining their size. Therefore, we cannot allow `extern` types here. Consult
441+
// t-opsem before removing this check.
442+
panic!("unsized arguments must not be `extern` types");
443+
}
432444
}
433445
}
434446
}

0 commit comments

Comments
 (0)