Skip to content

Commit 9098f05

Browse files
Rollup merge of #97188 - carbotaniuman:remove-null-assert, r=RalfJung
Remove unneeded null pointer asserts in ptr2int casts This removes an assert that a pointer with address 0 has no provenance. This change is needed to support permissive provenance work in Miri, and seems justified by `ptr.with_addr(0)` working and a discussion on Zulip regarding LLVM semantics. r? `@RalfJung`
2 parents 706aa59 + e246735 commit 9098f05

File tree

2 files changed

+1
-8
lines changed

2 files changed

+1
-8
lines changed

compiler/rustc_const_eval/src/interpret/cast.rs

-3
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,6 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
225225
let addr = u64::try_from(size.truncate(v)).unwrap();
226226

227227
let ptr = M::ptr_from_addr_cast(&self, addr);
228-
if addr == 0 {
229-
assert!(ptr.provenance.is_none(), "null pointer can never have an AllocId");
230-
}
231228
Scalar::from_maybe_pointer(ptr, self)
232229
}
233230

compiler/rustc_const_eval/src/interpret/memory.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -1149,11 +1149,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
11491149
Err(ptr) => ptr.into(),
11501150
Ok(bits) => {
11511151
let addr = u64::try_from(bits).unwrap();
1152-
let ptr = M::ptr_from_addr_transmute(&self, addr);
1153-
if addr == 0 {
1154-
assert!(ptr.provenance.is_none(), "null pointer can never have an AllocId");
1155-
}
1156-
ptr
1152+
M::ptr_from_addr_transmute(&self, addr)
11571153
}
11581154
},
11591155
)

0 commit comments

Comments
 (0)