-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CFI: Rewrite closure and coroutine instances to their trait method
- Loading branch information
Showing
3 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Verifies that casting a closure to a Fn trait object 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 | ||
|
||
#![feature(fn_traits)] | ||
fn main() { | ||
let f: &(dyn Fn()) = &(|| {}) as _; | ||
f.call(()); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Verifies that casting a closure to a Fn trait object 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 | ||
|
||
fn foo<'a, T>() -> Box<dyn Fn(&'a T) -> &'a T> { | ||
Box::new(|x| x) | ||
} | ||
|
||
fn main() { | ||
let x = 3; | ||
let f = foo(); | ||
f(&x); | ||
// FIXME remove once drops are working. | ||
std::mem::forget(f); | ||
} |