Skip to content

Commit c8ae02f

Browse files
CFI: Erase regions when projecting ADT to its transparent non-1zst field
1 parent a73bc4a commit c8ae02f

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/transform.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for TransformTy<'tcx> {
146146
!is_zst
147147
});
148148
if let Some(field) = field {
149-
let ty0 = self.tcx.type_of(field.did).instantiate(self.tcx, args);
149+
let ty0 = self.tcx.erase_regions(field.ty(self.tcx, args));
150150
// Generalize any repr(transparent) user-defined type that is either a
151151
// pointer or reference, and either references itself or any other type that
152152
// contains or references itself, to avoid a reference cycle.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//@ needs-sanitizer-cfi
2+
//@ compile-flags: -Ccodegen-units=1 -Clto -Ctarget-feature=-crt-static -Zsanitizer=cfi
3+
//@ no-prefer-dynamic
4+
//@ only-x86_64-unknown-linux-gnu
5+
//@ build-pass
6+
7+
pub trait Trait {}
8+
9+
impl Trait for i32 {}
10+
11+
#[repr(transparent)]
12+
struct BoxedTrait(Box<dyn Trait + 'static>);
13+
14+
fn hello(x: BoxedTrait) {}
15+
16+
fn main() {
17+
hello(BoxedTrait(Box::new(1)));
18+
}

0 commit comments

Comments
 (0)