2024-03-22 17:45:23 -05:00
|
|
|
// Verifies that casting a method to a function pointer works.
|
2024-03-25 12:23:55 -05:00
|
|
|
|
|
|
|
//@ revisions: cfi kcfi
|
|
|
|
// FIXME(#122848) Remove only-linux once OSX CFI binaries work
|
2024-03-22 17:45:23 -05:00
|
|
|
//@ only-linux
|
2024-03-25 12:23:55 -05:00
|
|
|
//@ [cfi] needs-sanitizer-cfi
|
|
|
|
//@ [kcfi] needs-sanitizer-kcfi
|
|
|
|
//@ compile-flags: -C target-feature=-crt-static
|
|
|
|
//@ [cfi] compile-flags: -C opt-level=0 -C codegen-units=1 -C lto
|
|
|
|
//@ [cfi] compile-flags: -C prefer-dynamic=off
|
|
|
|
//@ [cfi] compile-flags: -Z sanitizer=cfi
|
|
|
|
//@ [kcfi] compile-flags: -Z sanitizer=kcfi
|
|
|
|
//@ [kcfi] compile-flags: -C panic=abort -C prefer-dynamic=off
|
2024-03-22 17:45:23 -05:00
|
|
|
//@ run-pass
|
|
|
|
|
2024-03-25 12:23:55 -05:00
|
|
|
trait Foo {
|
|
|
|
fn foo(&self);
|
|
|
|
fn bar(&self);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct S;
|
|
|
|
|
|
|
|
impl Foo for S {
|
|
|
|
fn foo(&self) {}
|
|
|
|
#[track_caller]
|
|
|
|
fn bar(&self) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct S2 {
|
|
|
|
f: fn(&S)
|
|
|
|
}
|
|
|
|
|
|
|
|
impl S2 {
|
|
|
|
fn foo(&self, s: &S) {
|
|
|
|
(self.f)(s)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-22 17:45:23 -05:00
|
|
|
trait Trait1 {
|
|
|
|
fn foo(&self);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct Type1;
|
|
|
|
|
|
|
|
impl Trait1 for Type1 {
|
|
|
|
fn foo(&self) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let type1 = Type1 {};
|
|
|
|
let f = <Type1 as Trait1>::foo;
|
|
|
|
f(&type1);
|
2024-03-25 12:23:55 -05:00
|
|
|
// Check again with different optimization barriers
|
|
|
|
S2 { f: <S as Foo>::foo }.foo(&S);
|
|
|
|
// Check mismatched #[track_caller]
|
|
|
|
S2 { f: <S as Foo>::bar }.foo(&S)
|
2024-03-22 17:45:23 -05:00
|
|
|
}
|