Don't reset cast kind without also updating the operand in simplify_cast
This commit is contained in:
parent
c215e80aa9
commit
de7d4a840e
4 changed files with 15 additions and 13 deletions
|
@ -1367,16 +1367,17 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
|
|||
|
||||
fn simplify_cast(
|
||||
&mut self,
|
||||
kind: &mut CastKind,
|
||||
operand: &mut Operand<'tcx>,
|
||||
initial_kind: &mut CastKind,
|
||||
initial_operand: &mut Operand<'tcx>,
|
||||
to: Ty<'tcx>,
|
||||
location: Location,
|
||||
) -> Option<VnIndex> {
|
||||
use CastKind::*;
|
||||
use rustc_middle::ty::adjustment::PointerCoercion::*;
|
||||
|
||||
let mut from = operand.ty(self.local_decls, self.tcx);
|
||||
let mut value = self.simplify_operand(operand, location)?;
|
||||
let mut from = initial_operand.ty(self.local_decls, self.tcx);
|
||||
let mut kind = *initial_kind;
|
||||
let mut value = self.simplify_operand(initial_operand, location)?;
|
||||
if from == to {
|
||||
return Some(value);
|
||||
}
|
||||
|
@ -1400,7 +1401,7 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
|
|||
&& to.is_unsafe_ptr()
|
||||
&& self.pointers_have_same_metadata(from, to)
|
||||
{
|
||||
*kind = PtrToPtr;
|
||||
kind = PtrToPtr;
|
||||
was_updated_this_iteration = true;
|
||||
}
|
||||
|
||||
|
@ -1443,7 +1444,7 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
|
|||
to: inner_to,
|
||||
} = *self.get(value)
|
||||
{
|
||||
let new_kind = match (inner_kind, *kind) {
|
||||
let new_kind = match (inner_kind, kind) {
|
||||
// Even if there's a narrowing cast in here that's fine, because
|
||||
// things like `*mut [i32] -> *mut i32 -> *const i32` and
|
||||
// `*mut [i32] -> *const [i32] -> *const i32` can skip the middle in MIR.
|
||||
|
@ -1471,7 +1472,7 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
|
|||
_ => None,
|
||||
};
|
||||
if let Some(new_kind) = new_kind {
|
||||
*kind = new_kind;
|
||||
kind = new_kind;
|
||||
from = inner_from;
|
||||
value = inner_value;
|
||||
was_updated_this_iteration = true;
|
||||
|
@ -1489,10 +1490,11 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
|
|||
}
|
||||
|
||||
if was_ever_updated && let Some(op) = self.try_as_operand(value, location) {
|
||||
*operand = op;
|
||||
*initial_operand = op;
|
||||
*initial_kind = kind;
|
||||
}
|
||||
|
||||
Some(self.insert(Value::Cast { kind: *kind, value, from, to }))
|
||||
Some(self.insert(Value::Cast { kind, value, from, to }))
|
||||
}
|
||||
|
||||
fn simplify_len(&mut self, place: &mut Place<'tcx>, location: Location) -> Option<VnIndex> {
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
// EMIT_MIR dont_reset_cast_kind_without_updating_operand.test.GVN.diff
|
||||
|
||||
fn test() {
|
||||
let vp_ctx: &Box<()>= &Box::new(());
|
||||
let vp_ctx: &Box<()> = &Box::new(());
|
||||
let slf: *const () = &raw const **vp_ctx;
|
||||
let bytes = std::ptr::slice_from_raw_parts(slf, 1);
|
||||
let _x = foo(bytes);
|
||||
|
@ -12,4 +12,4 @@ fn test() {
|
|||
|
||||
fn foo(bytes: *const [()]) -> *mut () {
|
||||
bytes as *mut ()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -141,7 +141,7 @@
|
|||
StorageLive(_8);
|
||||
_8 = copy _5;
|
||||
- _7 = copy _8 as *mut () (PtrToPtr);
|
||||
+ _7 = copy _5 as *mut () (Transmute);
|
||||
+ _7 = copy _5 as *mut () (PtrToPtr);
|
||||
StorageDead(_8);
|
||||
StorageDead(_7);
|
||||
- StorageDead(_5);
|
||||
|
|
|
@ -66,7 +66,7 @@
|
|||
StorageLive(_8);
|
||||
_8 = copy _5;
|
||||
- _7 = copy _8 as *mut () (PtrToPtr);
|
||||
+ _7 = copy _5 as *mut () (Transmute);
|
||||
+ _7 = copy _5 as *mut () (PtrToPtr);
|
||||
StorageDead(_8);
|
||||
StorageDead(_7);
|
||||
- StorageDead(_5);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue