diff options
| author | Ralf Jung <post@ralfj.de> | 2025-07-19 20:04:08 +0200 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2025-07-20 22:14:27 +0200 |
| commit | 3f9be406a6fd879a99a0eba33cc196fa2cb3957b (patch) | |
| tree | 640b295bc5b57132a450008fbb6cc38c7c72fb58 /compiler/rustc_const_eval/src/interpret/memory.rs | |
| parent | 9982d6462bedf1e793f7b2dbd655a4e57cdf67d4 (diff) | |
| download | rust-3f9be406a6fd879a99a0eba33cc196fa2cb3957b.tar.gz rust-3f9be406a6fd879a99a0eba33cc196fa2cb3957b.zip | |
fix handling of base address for TypeId allocations
Diffstat (limited to 'compiler/rustc_const_eval/src/interpret/memory.rs')
| -rw-r--r-- | compiler/rustc_const_eval/src/interpret/memory.rs | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/compiler/rustc_const_eval/src/interpret/memory.rs b/compiler/rustc_const_eval/src/interpret/memory.rs index 20c8e983cea..34297a61648 100644 --- a/compiler/rustc_const_eval/src/interpret/memory.rs +++ b/compiler/rustc_const_eval/src/interpret/memory.rs @@ -67,8 +67,10 @@ pub enum AllocKind { LiveData, /// A function allocation (that fn ptrs point to). Function, - /// A "virtual" allocation, used for vtables and TypeId. - Virtual, + /// A vtable allocation. + VTable, + /// A TypeId allocation. + TypeId, /// A dead allocation. Dead, } @@ -952,7 +954,8 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { let kind = match global_alloc { GlobalAlloc::Static { .. } | GlobalAlloc::Memory { .. } => AllocKind::LiveData, GlobalAlloc::Function { .. } => bug!("We already checked function pointers above"), - GlobalAlloc::VTable { .. } | GlobalAlloc::TypeId { .. } => AllocKind::Virtual, + GlobalAlloc::VTable { .. } => AllocKind::VTable, + GlobalAlloc::TypeId { .. } => AllocKind::TypeId, }; return AllocInfo::new(size, align, kind, mutbl); } @@ -1617,6 +1620,13 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { match self.ptr_try_get_alloc_id(ptr, 0) { Ok((alloc_id, offset, _)) => { let info = self.get_alloc_info(alloc_id); + if matches!(info.kind, AllocKind::TypeId) { + // We *could* actually precisely answer this question since here, + // the offset *is* the integer value. But the entire point of making + // this a pointer is not to leak the integer value, so we say everything + // might be null. + return interp_ok(true); + } // If the pointer is in-bounds (including "at the end"), it is definitely not null. if offset <= info.size { return interp_ok(false); |
