mirror of
https://github.com/rust-lang/rust.git
synced 2024-10-31 14:31:55 +00:00
Compute unsizing casts in GVN.
This commit is contained in:
parent
1f544ca0cc
commit
304b4ad8b9
@ -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,
|
||||
src: &OpTy<'tcx, M::Provenance>,
|
||||
cast_ty: TyAndLayout<'tcx>,
|
||||
|
@ -551,6 +551,16 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
|
||||
}
|
||||
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,
|
||||
},
|
||||
};
|
||||
|
@ -31,16 +31,17 @@
|
||||
StorageDead(_3);
|
||||
StorageLive(_6);
|
||||
_6 = const 1_usize;
|
||||
_7 = Len((*_2));
|
||||
- _7 = Len((*_2));
|
||||
- _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];
|
||||
+ _8 = Lt(const 1_usize, _7);
|
||||
+ assert(move _8, "index out of bounds: the length is {} but the index is {}", move _7, const 1_usize) -> [success: bb1, unwind unreachable];
|
||||
+ _7 = const 3_usize;
|
||||
+ _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: {
|
||||
- _1 = (*_2)[_6];
|
||||
+ _1 = (*_2)[1 of 2];
|
||||
+ _1 = const 2_u32;
|
||||
StorageDead(_6);
|
||||
StorageDead(_4);
|
||||
StorageDead(_2);
|
||||
|
@ -31,16 +31,17 @@
|
||||
StorageDead(_3);
|
||||
StorageLive(_6);
|
||||
_6 = const 1_usize;
|
||||
_7 = Len((*_2));
|
||||
- _7 = Len((*_2));
|
||||
- _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];
|
||||
+ _8 = Lt(const 1_usize, _7);
|
||||
+ assert(move _8, "index out of bounds: the length is {} but the index is {}", move _7, const 1_usize) -> [success: bb1, unwind continue];
|
||||
+ _7 = const 3_usize;
|
||||
+ _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: {
|
||||
- _1 = (*_2)[_6];
|
||||
+ _1 = (*_2)[1 of 2];
|
||||
+ _1 = const 2_u32;
|
||||
StorageDead(_6);
|
||||
StorageDead(_4);
|
||||
StorageDead(_2);
|
||||
|
@ -31,16 +31,17 @@
|
||||
StorageDead(_3);
|
||||
StorageLive(_6);
|
||||
_6 = const 1_usize;
|
||||
_7 = Len((*_2));
|
||||
- _7 = Len((*_2));
|
||||
- _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];
|
||||
+ _8 = Lt(const 1_usize, _7);
|
||||
+ assert(move _8, "index out of bounds: the length is {} but the index is {}", move _7, const 1_usize) -> [success: bb1, unwind unreachable];
|
||||
+ _7 = const 3_usize;
|
||||
+ _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: {
|
||||
- _1 = (*_2)[_6];
|
||||
+ _1 = (*_2)[1 of 2];
|
||||
+ _1 = const 2_u32;
|
||||
StorageDead(_6);
|
||||
StorageDead(_4);
|
||||
StorageDead(_2);
|
||||
|
@ -31,16 +31,17 @@
|
||||
StorageDead(_3);
|
||||
StorageLive(_6);
|
||||
_6 = const 1_usize;
|
||||
_7 = Len((*_2));
|
||||
- _7 = Len((*_2));
|
||||
- _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];
|
||||
+ _8 = Lt(const 1_usize, _7);
|
||||
+ assert(move _8, "index out of bounds: the length is {} but the index is {}", move _7, const 1_usize) -> [success: bb1, unwind continue];
|
||||
+ _7 = const 3_usize;
|
||||
+ _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: {
|
||||
- _1 = (*_2)[_6];
|
||||
+ _1 = (*_2)[1 of 2];
|
||||
+ _1 = const 2_u32;
|
||||
StorageDead(_6);
|
||||
StorageDead(_4);
|
||||
StorageDead(_2);
|
||||
|
@ -8,9 +8,7 @@ fn main() {
|
||||
// CHECK-LABEL: fn main(
|
||||
// CHECK: debug a => [[a:_.*]];
|
||||
// CHECK: [[slice:_.*]] = const {{.*}} as &[u32] (PointerCoercion(Unsize));
|
||||
// FIXME(cjgillot) simplify Len and projection into unsized slice.
|
||||
// CHECK-NOT: assert(const true,
|
||||
// CHECK: [[a]] = (*[[slice]])[1 of 2];
|
||||
// CHECK-NOT: [[a]] = const 2_u32;
|
||||
// CHECK: assert(const true,
|
||||
// CHECK: [[a]] = const 2_u32;
|
||||
let a = (&[1u32, 2, 3] as &[u32])[1];
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user