Skip to content

Commit

Permalink
Fix handling of adjustment casts.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjgillot committed Feb 13, 2024
1 parent 7ec9601 commit a97e4af
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions compiler/rustc_mir_transform/src/gvn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -561,18 +561,22 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
.ok()?;
dest.into()
}
CastKind::FnPtrToPtr
| CastKind::PtrToPtr
| CastKind::PointerCoercion(
CastKind::FnPtrToPtr | CastKind::PtrToPtr => {
let src = self.evaluated[value].as_ref()?;
let src = self.ecx.read_immediate(src).ok()?;
let to = self.ecx.layout_of(to).ok()?;
let ret = self.ecx.ptr_to_ptr(&src, to).ok()?;
ret.into()
}
CastKind::PointerCoercion(
ty::adjustment::PointerCoercion::MutToConstPointer
| ty::adjustment::PointerCoercion::ArrayToPointer
| ty::adjustment::PointerCoercion::UnsafeFnPointer,
) => {
let src = self.evaluated[value].as_ref()?;
let src = self.ecx.read_immediate(src).ok()?;
let to = self.ecx.layout_of(to).ok()?;
let ret = self.ecx.ptr_to_ptr(&src, to).ok()?;
ret.into()
ImmTy::from_immediate(*src, to).into()
}
_ => return None,
},
Expand Down

0 comments on commit a97e4af

Please sign in to comment.