Skip to content

Commit

Permalink
Unrolled build for rust-lang#125508
Browse files Browse the repository at this point in the history
Rollup merge of rust-lang#125508 - scottmcm:fix-125506, r=Nilstrieb

Stop SRoA'ing `DynMetadata` in MIR

Fixes rust-lang#125506
  • Loading branch information
rust-timer authored May 26, 2024
2 parents a6a017d + d7248d7 commit 7545461
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions compiler/rustc_mir_transform/src/sroa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ fn escaping_locals<'tcx>(
// Exclude #[repr(simd)] types so that they are not de-optimized into an array
return true;
}
if Some(def.did()) == tcx.lang_items().dyn_metadata() {
// codegen wants to see the `DynMetadata<T>`,
// not the inner reference-to-opaque-type.
return true;
}
// We already excluded unions and enums, so this ADT must have one variant
let variant = def.variant(FIRST_VARIANT);
if variant.fields.len() > 1 {
Expand Down
19 changes: 19 additions & 0 deletions tests/ui/mir/dyn_metadata_sroa.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//@ run-pass
//@ compile-flags: -Zmir-opt-level=5 -Zvalidate-mir

#![feature(ptr_metadata)]

// Regression for <https://github.com/rust-lang/rust/issues/125506>,
// which failed because of SRoA would project into `DynMetadata`.

trait Foo {}

struct Bar;

impl Foo for Bar {}

fn main() {
let a: *mut dyn Foo = &mut Bar;

let _d = a.to_raw_parts().0 as usize;
}

0 comments on commit 7545461

Please sign in to comment.