Rollup merge of #122879 - maurer:callsite-instances, r=workingjubilee
CFI: Strip auto traits off Virtual calls We already use `Instance` at declaration sites when available to glean additional information about possible abstractions of the type in use. This does the same when possible at callsites as well. The primary purpose of this change is to allow CFI to alter how it generates type information for indirect calls through `Virtual` instances. This is needed for the "separate machinery" version of my approach to the vtable issues (#122573), because we need to respond differently to a `Virtual` call to the same type as a non-virtual call, specifically [stripping auto traits off the receiver's `Self`](https://github.com/rust-lang/rust/pull/122573/commits/54b15b0c36d4638167732a0542ed0e34ecf17d7c) because there isn't a separate vtable for `Foo` vs `Foo + Send`. This would also make a more general underlying mechanism that could be used by rcvalle's [proposed drop detection / encoding](https://github.com/rust-lang/rust/pull/116404/commits/edcd1e20a1a69a8590d8ca47b31634854a40e3fb) if we end up using his approach, as we could condition out on the `def_id` in the CFI code rather than requiring the generating code to explicitly note whether it was calling drop.
This commit is contained in:
commit
992aa1edb6
14 changed files with 155 additions and 58 deletions
22
tests/ui/sanitizer/cfi-virtual-auto.rs
Normal file
22
tests/ui/sanitizer/cfi-virtual-auto.rs
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
// Tests that calling a trait object method on a trait object with additional auto traits works.
|
||||
|
||||
//@ 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
|
||||
|
||||
trait Foo {
|
||||
fn foo(&self);
|
||||
}
|
||||
|
||||
struct Bar;
|
||||
impl Foo for Bar {
|
||||
fn foo(&self) {}
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
let x: &(dyn Foo + Send) = &Bar;
|
||||
x.foo();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue