Skip to content

Commit b5ecb9d

Browse files
committed
more targeted errors when extern types end up in places they should not
1 parent 0908f17 commit b5ecb9d

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

Diff for: 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() {

Diff for: compiler/rustc_ty_utils/src/abi.rs

+9
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,15 @@ fn fn_abi_sanity_check<'tcx>(
429429
PassMode::Indirect { meta_attrs: Some(_), on_stack, .. } => {
430430
// With metadata. Must be unsized and not on the stack.
431431
assert!(arg.layout.is_unsized() && !on_stack);
432+
// Also, must not be `extern` type.
433+
let tail = cx.tcx.struct_tail_with_normalize(arg.layout.ty, |ty| ty, || {});
434+
if matches!(tail.kind(), ty::Foreign(..)) {
435+
// These types do not have metadata, so having `meta_attrs` is bogus.
436+
// Conceptually, unsized arguments must be copied around, which requires dynamically
437+
// determining their size. Therefore, we cannot allow `extern` types here. Consult
438+
// t-opsem before removing this check.
439+
panic!("unsized arguments must not be `extern` types");
440+
}
432441
}
433442
}
434443
}

0 commit comments

Comments
 (0)