Skip to content

Commit 9c905f8

Browse files
committed
Auto merge of #58271 - eddyb:opaque-extern-type, r=<try>
rustc_codegen_llvm: use opaque LLVM structs for `extern type`. Mostly an experiment, @RalfJung suggested it could be used to inform LLVM that for e.g.: ```rust extern { type Foo; static BAR: Foo; } ``` `BAR` does not have a known size, and therefore nothing can be assumed about the validity of accesses at arbitrary offsets.
2 parents ad43389 + 56240ec commit 9c905f8

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/librustc_codegen_llvm/type_of.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,10 @@ fn uncached_llvm_type<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
9090
match name {
9191
None => {
9292
let (llfields, packed) = struct_llfields(cx, layout);
93-
cx.type_struct( &llfields, packed)
93+
cx.type_struct(&llfields, packed)
9494
}
9595
Some(ref name) => {
96-
let llty = cx.type_named_struct( name);
96+
let llty = cx.type_named_struct(name);
9797
*defer = Some((llty, layout));
9898
llty
9999
}
@@ -298,8 +298,15 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyLayout<'tcx> {
298298
cx.lltypes.borrow_mut().insert((self.ty, variant_index), llty);
299299

300300
if let Some((llty, layout)) = defer {
301-
let (llfields, packed) = struct_llfields(cx, layout);
302-
cx.set_struct_body(llty, &llfields, packed)
301+
match layout.ty.sty {
302+
// Leave an `extern type` fully opaque (LLVM "unsized").
303+
ty::Foreign(..) => {}
304+
305+
_ => {
306+
let (llfields, packed) = struct_llfields(cx, layout);
307+
cx.set_struct_body(llty, &llfields, packed)
308+
}
309+
}
303310
}
304311

305312
llty

0 commit comments

Comments
 (0)