Auto merge of #123071 - rcvalle:rust-cfi-fix-method-fn-ptr-cast, r=compiler-errors
CFI: Fix methods as function pointer cast Fix casting between methods and function pointers by assigning a secondary type id to methods with their concrete self so they can be used as function pointers. This was split off from #116404. cc `@compiler-errors` `@workingjubilee`
This commit is contained in:
commit
58dcd1fdb9
5 changed files with 84 additions and 27 deletions
23
tests/ui/sanitizer/cfi-method-fn-ptr-cast.rs
Normal file
23
tests/ui/sanitizer/cfi-method-fn-ptr-cast.rs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
// Verifies that casting a method to a function pointer works.
|
||||
//
|
||||
// FIXME(#122848): Remove only-linux when fixed.
|
||||
//@ only-linux
|
||||
//@ needs-sanitizer-cfi
|
||||
//@ compile-flags: -Clto -Copt-level=0 -Cprefer-dynamic=off -Ctarget-feature=-crt-static -Zsanitizer=cfi
|
||||
//@ run-pass
|
||||
|
||||
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);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue