Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Stop SRoA'ing DynMetadata in MIR
  • Loading branch information
scottmcm committed May 25, 2024
commit d7248d7b71fd756bef62e98b52ee1110f8d3a3c4
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;
}