Compute unsizing casts in GVN.
This commit is contained in:
parent
1f544ca0cc
commit
304b4ad8b9
7 changed files with 33 additions and 21 deletions
|
@ -415,7 +415,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn unsize_into(
|
pub fn unsize_into(
|
||||||
&mut self,
|
&mut self,
|
||||||
src: &OpTy<'tcx, M::Provenance>,
|
src: &OpTy<'tcx, M::Provenance>,
|
||||||
cast_ty: TyAndLayout<'tcx>,
|
cast_ty: TyAndLayout<'tcx>,
|
||||||
|
|
|
@ -551,6 +551,16 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
|
||||||
}
|
}
|
||||||
value.offset(Size::ZERO, to, &self.ecx).ok()?
|
value.offset(Size::ZERO, to, &self.ecx).ok()?
|
||||||
}
|
}
|
||||||
|
CastKind::PointerCoercion(ty::adjustment::PointerCoercion::Unsize) => {
|
||||||
|
let src = self.evaluated[value].as_ref()?;
|
||||||
|
let to = self.ecx.layout_of(to).ok()?;
|
||||||
|
let dest = self.ecx.allocate(to, MemoryKind::Stack).ok()?;
|
||||||
|
self.ecx.unsize_into(src, to, &dest.clone().into()).ok()?;
|
||||||
|
self.ecx
|
||||||
|
.alloc_mark_immutable(dest.ptr().provenance.unwrap().alloc_id())
|
||||||
|
.ok()?;
|
||||||
|
dest.into()
|
||||||
|
}
|
||||||
_ => return None,
|
_ => return None,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -31,16 +31,17 @@
|
||||||
StorageDead(_3);
|
StorageDead(_3);
|
||||||
StorageLive(_6);
|
StorageLive(_6);
|
||||||
_6 = const 1_usize;
|
_6 = const 1_usize;
|
||||||
_7 = Len((*_2));
|
- _7 = Len((*_2));
|
||||||
- _8 = Lt(_6, _7);
|
- _8 = Lt(_6, _7);
|
||||||
- assert(move _8, "index out of bounds: the length is {} but the index is {}", move _7, _6) -> [success: bb1, unwind unreachable];
|
- assert(move _8, "index out of bounds: the length is {} but the index is {}", move _7, _6) -> [success: bb1, unwind unreachable];
|
||||||
+ _8 = Lt(const 1_usize, _7);
|
+ _7 = const 3_usize;
|
||||||
+ assert(move _8, "index out of bounds: the length is {} but the index is {}", move _7, const 1_usize) -> [success: bb1, unwind unreachable];
|
+ _8 = const true;
|
||||||
|
+ assert(const true, "index out of bounds: the length is {} but the index is {}", const 3_usize, const 1_usize) -> [success: bb1, unwind unreachable];
|
||||||
}
|
}
|
||||||
|
|
||||||
bb1: {
|
bb1: {
|
||||||
- _1 = (*_2)[_6];
|
- _1 = (*_2)[_6];
|
||||||
+ _1 = (*_2)[1 of 2];
|
+ _1 = const 2_u32;
|
||||||
StorageDead(_6);
|
StorageDead(_6);
|
||||||
StorageDead(_4);
|
StorageDead(_4);
|
||||||
StorageDead(_2);
|
StorageDead(_2);
|
||||||
|
|
|
@ -31,16 +31,17 @@
|
||||||
StorageDead(_3);
|
StorageDead(_3);
|
||||||
StorageLive(_6);
|
StorageLive(_6);
|
||||||
_6 = const 1_usize;
|
_6 = const 1_usize;
|
||||||
_7 = Len((*_2));
|
- _7 = Len((*_2));
|
||||||
- _8 = Lt(_6, _7);
|
- _8 = Lt(_6, _7);
|
||||||
- assert(move _8, "index out of bounds: the length is {} but the index is {}", move _7, _6) -> [success: bb1, unwind continue];
|
- assert(move _8, "index out of bounds: the length is {} but the index is {}", move _7, _6) -> [success: bb1, unwind continue];
|
||||||
+ _8 = Lt(const 1_usize, _7);
|
+ _7 = const 3_usize;
|
||||||
+ assert(move _8, "index out of bounds: the length is {} but the index is {}", move _7, const 1_usize) -> [success: bb1, unwind continue];
|
+ _8 = const true;
|
||||||
|
+ assert(const true, "index out of bounds: the length is {} but the index is {}", const 3_usize, const 1_usize) -> [success: bb1, unwind continue];
|
||||||
}
|
}
|
||||||
|
|
||||||
bb1: {
|
bb1: {
|
||||||
- _1 = (*_2)[_6];
|
- _1 = (*_2)[_6];
|
||||||
+ _1 = (*_2)[1 of 2];
|
+ _1 = const 2_u32;
|
||||||
StorageDead(_6);
|
StorageDead(_6);
|
||||||
StorageDead(_4);
|
StorageDead(_4);
|
||||||
StorageDead(_2);
|
StorageDead(_2);
|
||||||
|
|
|
@ -31,16 +31,17 @@
|
||||||
StorageDead(_3);
|
StorageDead(_3);
|
||||||
StorageLive(_6);
|
StorageLive(_6);
|
||||||
_6 = const 1_usize;
|
_6 = const 1_usize;
|
||||||
_7 = Len((*_2));
|
- _7 = Len((*_2));
|
||||||
- _8 = Lt(_6, _7);
|
- _8 = Lt(_6, _7);
|
||||||
- assert(move _8, "index out of bounds: the length is {} but the index is {}", move _7, _6) -> [success: bb1, unwind unreachable];
|
- assert(move _8, "index out of bounds: the length is {} but the index is {}", move _7, _6) -> [success: bb1, unwind unreachable];
|
||||||
+ _8 = Lt(const 1_usize, _7);
|
+ _7 = const 3_usize;
|
||||||
+ assert(move _8, "index out of bounds: the length is {} but the index is {}", move _7, const 1_usize) -> [success: bb1, unwind unreachable];
|
+ _8 = const true;
|
||||||
|
+ assert(const true, "index out of bounds: the length is {} but the index is {}", const 3_usize, const 1_usize) -> [success: bb1, unwind unreachable];
|
||||||
}
|
}
|
||||||
|
|
||||||
bb1: {
|
bb1: {
|
||||||
- _1 = (*_2)[_6];
|
- _1 = (*_2)[_6];
|
||||||
+ _1 = (*_2)[1 of 2];
|
+ _1 = const 2_u32;
|
||||||
StorageDead(_6);
|
StorageDead(_6);
|
||||||
StorageDead(_4);
|
StorageDead(_4);
|
||||||
StorageDead(_2);
|
StorageDead(_2);
|
||||||
|
|
|
@ -31,16 +31,17 @@
|
||||||
StorageDead(_3);
|
StorageDead(_3);
|
||||||
StorageLive(_6);
|
StorageLive(_6);
|
||||||
_6 = const 1_usize;
|
_6 = const 1_usize;
|
||||||
_7 = Len((*_2));
|
- _7 = Len((*_2));
|
||||||
- _8 = Lt(_6, _7);
|
- _8 = Lt(_6, _7);
|
||||||
- assert(move _8, "index out of bounds: the length is {} but the index is {}", move _7, _6) -> [success: bb1, unwind continue];
|
- assert(move _8, "index out of bounds: the length is {} but the index is {}", move _7, _6) -> [success: bb1, unwind continue];
|
||||||
+ _8 = Lt(const 1_usize, _7);
|
+ _7 = const 3_usize;
|
||||||
+ assert(move _8, "index out of bounds: the length is {} but the index is {}", move _7, const 1_usize) -> [success: bb1, unwind continue];
|
+ _8 = const true;
|
||||||
|
+ assert(const true, "index out of bounds: the length is {} but the index is {}", const 3_usize, const 1_usize) -> [success: bb1, unwind continue];
|
||||||
}
|
}
|
||||||
|
|
||||||
bb1: {
|
bb1: {
|
||||||
- _1 = (*_2)[_6];
|
- _1 = (*_2)[_6];
|
||||||
+ _1 = (*_2)[1 of 2];
|
+ _1 = const 2_u32;
|
||||||
StorageDead(_6);
|
StorageDead(_6);
|
||||||
StorageDead(_4);
|
StorageDead(_4);
|
||||||
StorageDead(_2);
|
StorageDead(_2);
|
||||||
|
|
|
@ -8,9 +8,7 @@ fn main() {
|
||||||
// CHECK-LABEL: fn main(
|
// CHECK-LABEL: fn main(
|
||||||
// CHECK: debug a => [[a:_.*]];
|
// CHECK: debug a => [[a:_.*]];
|
||||||
// CHECK: [[slice:_.*]] = const {{.*}} as &[u32] (PointerCoercion(Unsize));
|
// CHECK: [[slice:_.*]] = const {{.*}} as &[u32] (PointerCoercion(Unsize));
|
||||||
// FIXME(cjgillot) simplify Len and projection into unsized slice.
|
// CHECK: assert(const true,
|
||||||
// CHECK-NOT: assert(const true,
|
// CHECK: [[a]] = const 2_u32;
|
||||||
// CHECK: [[a]] = (*[[slice]])[1 of 2];
|
|
||||||
// CHECK-NOT: [[a]] = const 2_u32;
|
|
||||||
let a = (&[1u32, 2, 3] as &[u32])[1];
|
let a = (&[1u32, 2, 3] as &[u32])[1];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue