Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

miri: normalize struct tail in ABI compat check #120587

Merged
merged 1 commit into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 5 additions & 1 deletion compiler/rustc_const_eval/src/interpret/terminator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,11 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
if let (Some(caller), Some(callee)) = (pointee_ty(caller.ty)?, pointee_ty(callee.ty)?) {
// This is okay if they have the same metadata type.
let meta_ty = |ty: Ty<'tcx>| {
let (meta, only_if_sized) = ty.ptr_metadata_ty(*self.tcx, |ty| ty);
// Even if `ty` is normalized, the search for the unsized tail will project
// to fields, which can yield non-normalized types. So we need to provide a
// normalization function.
let normalize = |ty| self.tcx.normalize_erasing_regions(self.param_env, ty);
let (meta, only_if_sized) = ty.ptr_metadata_ty(*self.tcx, normalize);
assert!(
!only_if_sized,
"there should be no more 'maybe has that metadata' types during interpretation"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// regression test for an ICE: https://github.com/rust-lang/miri/issues/3282

trait Id {
type Assoc: ?Sized;
}

impl<T: ?Sized> Id for T {
type Assoc = T;
}

#[repr(transparent)]
struct Foo<T: ?Sized> {
field: <T as Id>::Assoc,
}

fn main() {
let x = unsafe { std::mem::transmute::<fn(&str), fn(&Foo<str>)>(|_| ()) };
let foo: &Foo<str> = unsafe { &*("uwu" as *const str as *const Foo<str>) };
x(foo);
}
Loading