rust/tests/ui/sanitizer/cfi-self-ref.rs
Matthew Maurer dec36c3d6e CFI: Support self_cell-like recursion
Current `transform_ty` attempts to avoid cycles when normalizing
`#[repr(transparent)]` types to their interior, but runs afoul of this
pattern used in `self_cell`:

```
struct X<T> {
  x: u8,
  p: PhantomData<T>,
}

 #[repr(transparent)]
struct Y(X<Y>);
```

When attempting to normalize Y, it will still cycle indefinitely. By
using a types-visited list, this will instead get expanded exactly
one layer deep to X<Y>, and then stop, not attempting to normalize `Y`
any further.
2024-03-22 23:02:05 +00:00

34 lines
677 B
Rust

// 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
use std::marker::PhantomData;
struct X<T> {
_x: u8,
p: PhantomData<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: PhantomData}));
}