diff options
| author | carbotaniuman <41451839+carbotaniuman@users.noreply.github.com> | 2022-05-13 12:30:25 -0500 |
|---|---|---|
| committer | carbotaniuman <41451839+carbotaniuman@users.noreply.github.com> | 2022-05-13 12:30:25 -0500 |
| commit | bd5fce65c60ae83f37d0a46bac4e09e9fd30b2c2 (patch) | |
| tree | e7a37ca5fc13b3efc60d94e1c979cae1dde08627 /compiler/rustc_const_eval/src/interpret/memory.rs | |
| parent | 0034bbca260bfa00798d70150970924221688ede (diff) | |
| download | rust-bd5fce65c60ae83f37d0a46bac4e09e9fd30b2c2.tar.gz rust-bd5fce65c60ae83f37d0a46bac4e09e9fd30b2c2.zip | |
Rustc changes for permissive provenance
Diffstat (limited to 'compiler/rustc_const_eval/src/interpret/memory.rs')
| -rw-r--r-- | compiler/rustc_const_eval/src/interpret/memory.rs | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/compiler/rustc_const_eval/src/interpret/memory.rs b/compiler/rustc_const_eval/src/interpret/memory.rs index e8ee0fe6ea6..0479a8c4a45 100644 --- a/compiler/rustc_const_eval/src/interpret/memory.rs +++ b/compiler/rustc_const_eval/src/interpret/memory.rs @@ -770,7 +770,9 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { if reachable.insert(id) { // This is a new allocation, add its relocations to `todo`. if let Some((_, alloc)) = self.memory.alloc_map.get(id) { - todo.extend(alloc.relocations().values().map(|tag| tag.get_alloc_id())); + todo.extend( + alloc.relocations().values().filter_map(|tag| tag.get_alloc_id()), + ); } } } @@ -805,7 +807,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> std::fmt::Debug for DumpAllocs<'a, allocs_to_print: &mut VecDeque<AllocId>, alloc: &Allocation<Tag, Extra>, ) -> std::fmt::Result { - for alloc_id in alloc.relocations().values().map(|tag| tag.get_alloc_id()) { + for alloc_id in alloc.relocations().values().filter_map(|tag| tag.get_alloc_id()) { allocs_to_print.push_back(alloc_id); } write!(fmt, "{}", display_allocation(tcx, alloc)) @@ -1125,7 +1127,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { Err(ptr) => ptr.into(), Ok(bits) => { let addr = u64::try_from(bits).unwrap(); - let ptr = M::ptr_from_addr(&self, addr); + let ptr = M::ptr_from_addr_transmute(&self, addr); if addr == 0 { assert!(ptr.provenance.is_none(), "null pointer can never have an AllocId"); } @@ -1165,10 +1167,14 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { ptr: Pointer<Option<M::PointerTag>>, ) -> Result<(AllocId, Size, M::TagExtra), u64> { match ptr.into_pointer_or_addr() { - Ok(ptr) => { - let (alloc_id, offset, extra) = M::ptr_get_alloc(self, ptr); - Ok((alloc_id, offset, extra)) - } + Ok(ptr) => match M::ptr_get_alloc(self, ptr) { + Some((alloc_id, offset, extra)) => Ok((alloc_id, offset, extra)), + None => { + assert!(M::PointerTag::OFFSET_IS_ADDR); + let (_, addr) = ptr.into_parts(); + Err(addr.bytes()) + } + }, Err(addr) => Err(addr.bytes()), } } |
