diff options
| author | Matthew Maurer <mmaurer@google.com> | 2024-03-15 18:44:40 +0000 |
|---|---|---|
| committer | Matthew Maurer <mmaurer@google.com> | 2024-03-23 18:30:45 +0000 |
| commit | f434c27067085d72c7770da3b6d4e0bc316fd267 (patch) | |
| tree | de6904f03fafbbff57d753505e7f3df126b2c87b /tests | |
| parent | 7967915c7b456d59fd963260822d3cf583969948 (diff) | |
| download | rust-f434c27067085d72c7770da3b6d4e0bc316fd267.tar.gz rust-f434c27067085d72c7770da3b6d4e0bc316fd267.zip | |
CFI: Strip auto traits off Self for virtual calls
Additional trait bounds beyond the principal trait and its implications are not possible in the vtable. This means that if a receiver is `&dyn Foo + Send`, the function will only be expecting `&dyn Foo`. This strips those auto traits off before CFI encoding.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ui/sanitizer/cfi-virtual-auto.rs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/ui/sanitizer/cfi-virtual-auto.rs b/tests/ui/sanitizer/cfi-virtual-auto.rs new file mode 100644 index 00000000000..7a0c246a412 --- /dev/null +++ b/tests/ui/sanitizer/cfi-virtual-auto.rs @@ -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(); +} |
