Add CastKind::Transmute to MIR

Updates `interpret`, `codegen_ssa`, and `codegen_cranelift` to consume the new cast instead of the intrinsic.

Includes `CastTransmute` for custom MIR building, to be able to test the extra UB.
This commit is contained in:
Scott McMurray 2023-02-24 18:32:52 -08:00
parent a266f11990
commit 64cce5fc7d
55 changed files with 955 additions and 190 deletions

View file

@ -133,6 +133,22 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
bug!()
}
}
Transmute => {
assert!(src.layout.is_sized());
assert!(dest.layout.is_sized());
if src.layout.size != dest.layout.size {
throw_ub_format!(
"transmuting from {}-byte type to {}-byte type: `{}` -> `{}`",
src.layout.size.bytes(),
dest.layout.size.bytes(),
src.layout.ty,
dest.layout.ty,
);
}
self.copy_op(src, dest, /*allow_transmute*/ true)?;
}
}
Ok(())
}