diff options
| author | bors <bors@rust-lang.org> | 2025-07-21 19:48:22 +0000 | 
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2025-07-21 19:48:22 +0000 | 
| commit | 9748d87dc70a9a6725c5dbd76ce29d04752b4f90 (patch) | |
| tree | 4cffbc92abe5995b0348e464ffe6a256f973e653 /compiler/rustc_const_eval | |
| parent | 3f9f20f71dd945fe7d044e274094a53c90788269 (diff) | |
| parent | 6628a4afb5d08555f09878a48f0c4179e7582aa2 (diff) | |
| download | rust-9748d87dc70a9a6725c5dbd76ce29d04752b4f90.tar.gz rust-9748d87dc70a9a6725c5dbd76ce29d04752b4f90.zip | |
Auto merge of #144269 - jieyouxu:rollup-137ysl2, r=jieyouxu
Rollup of 14 pull requests Successful merges: - rust-lang/rust#142097 (gpu offload host code generation) - rust-lang/rust#143430 (Lower extra lifetimes before normal generic params.) - rust-lang/rust#143768 (Constify Try, From, TryFrom and relevant traits) - rust-lang/rust#143816 (Implement `check` for compiletest and RA using tool macro) - rust-lang/rust#143985 (rustc_public: de-StableMIR-ize) - rust-lang/rust#144027 (clippy: make tests work in stage 1) - rust-lang/rust#144080 (Mitigate `#[align]` name resolution ambiguity regression with a rename) - rust-lang/rust#144176 (Add approval blocking labels for new bors) - rust-lang/rust#144187 (fix handling of base address for TypeId allocations) - rust-lang/rust#144212 (Remove the ptr_unique lang item) - rust-lang/rust#144243 (Subtree update of `rust-analyzer`) - rust-lang/rust#144246 (Don't use another main test file as auxiliary) - rust-lang/rust#144251 (rustc-dev-guide subtree update) - rust-lang/rust#144254 (opt-dist: make `artifact-dir` an absolute path for `opt-dist local`) r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_const_eval')
| -rw-r--r-- | compiler/rustc_const_eval/src/const_eval/machine.rs | 18 | ||||
| -rw-r--r-- | compiler/rustc_const_eval/src/interpret/memory.rs | 16 | 
2 files changed, 18 insertions, 16 deletions
| diff --git a/compiler/rustc_const_eval/src/const_eval/machine.rs b/compiler/rustc_const_eval/src/const_eval/machine.rs index f24fb18f83b..a18ae79f318 100644 --- a/compiler/rustc_const_eval/src/const_eval/machine.rs +++ b/compiler/rustc_const_eval/src/const_eval/machine.rs @@ -279,23 +279,15 @@ impl<'tcx> CompileTimeInterpCx<'tcx> { fn guaranteed_cmp(&mut self, a: Scalar, b: Scalar) -> InterpResult<'tcx, u8> { interp_ok(match (a, b) { // Comparisons between integers are always known. - (Scalar::Int { .. }, Scalar::Int { .. }) => { - if a == b { - 1 - } else { - 0 - } - } - // Comparisons of abstract pointers with null pointers are known if the pointer - // is in bounds, because if they are in bounds, the pointer can't be null. - // Inequality with integers other than null can never be known for sure. - (Scalar::Int(int), ptr @ Scalar::Ptr(..)) - | (ptr @ Scalar::Ptr(..), Scalar::Int(int)) + (Scalar::Int(a), Scalar::Int(b)) => (a == b) as u8, + // Comparisons of null with an arbitrary scalar can be known if `scalar_may_be_null` + // indicates that the scalar can definitely *not* be null. + (Scalar::Int(int), ptr) | (ptr, Scalar::Int(int)) if int.is_null() && !self.scalar_may_be_null(ptr)? => { 0 } - // Equality with integers can never be known for sure. + // Other ways of comparing integers and pointers can never be known for sure. (Scalar::Int { .. }, Scalar::Ptr(..)) | (Scalar::Ptr(..), Scalar::Int { .. }) => 2, // FIXME: return a `1` for when both sides are the same pointer, *except* that // some things (like functions and vtables) do not have stable addresses 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); | 
