Skip to content

Instantly share code, notes, and snippets.

@maurer
Created March 22, 2024 16:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maurer/2e41856b577eeaa8a5f303911125ea46 to your computer and use it in GitHub Desktop.
Save maurer/2e41856b577eeaa8a5f303911125ea46 to your computer and use it in GitHub Desktop.
// 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