Created
March 22, 2024 16:59
-
-
Save maurer/2e41856b577eeaa8a5f303911125ea46 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Check that encoding self-referential types works with #[repr(transparent)] | |
//@ needs-sanitizer-cfi | |
// FIXME(#122848) Remove only-linux once OSX CFI binaries work | |
//@ only-linux | |
//@ compile-flags: --crate-type=bin -Cprefer-dynamic=off -Clto -Zsanitizer=cfi | |
//@ compile-flags: -C target-feature=-crt-static -C codegen-units=1 -C opt-level=0 | |
//@ run-pass | |
struct X<T> { | |
_x: u8, | |
p: *mut T, | |
} | |
#[repr(transparent)] | |
struct Y(X<Y>); | |
trait Fooable { | |
fn foo(&self, y: Y); | |
} | |
struct Bar; | |
impl Fooable for Bar { | |
fn foo(&self, _: Y) {} | |
} | |
fn main() { | |
let x = &Bar as &dyn Fooable; | |
x.foo(Y(X {_x: 0, p: std::ptr::null_mut()})); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment