From f4861f3251c9f4ef4a0e2e8a2b6778be9b3d872c Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 25 Jul 2021 11:31:57 +0200 Subject: [PATCH] Miri: santiy check that null pointer can never have an AllocId --- compiler/rustc_mir/src/interpret/memory.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_mir/src/interpret/memory.rs b/compiler/rustc_mir/src/interpret/memory.rs index 6dcd944a1c3f2..0396806f822fb 100644 --- a/compiler/rustc_mir/src/interpret/memory.rs +++ b/compiler/rustc_mir/src/interpret/memory.rs @@ -1142,7 +1142,11 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> { Err(ptr) => ptr.into(), Ok(bits) => { let addr = u64::try_from(bits).unwrap(); - M::ptr_from_addr(&self, addr) + let ptr = M::ptr_from_addr(&self, addr); + if addr == 0 { + assert!(ptr.provenance.is_none(), "null pointer can never have an AllocId"); + } + ptr } } }