diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2022-02-25 14:14:39 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-02-25 14:14:39 +0100 |
| commit | cf3bb098881da40eed6ce7ad913a7e5d904663e2 (patch) | |
| tree | 06d83d088c197a7e7d5c90c965f3a0847e4273c7 /compiler/rustc_const_eval/src/const_eval | |
| parent | f9f97b661a0160aa99083ac5c5b98a47f0778292 (diff) | |
| parent | d8064d7d49073ff9962369a40678c934d700f7e0 (diff) | |
| download | rust-cf3bb098881da40eed6ce7ad913a7e5d904663e2.tar.gz rust-cf3bb098881da40eed6ce7ad913a7e5d904663e2.zip | |
Rollup merge of #94343 - RalfJung:fn-ptr, r=oli-obk
Miri fn ptr check: don't use conservative null check In https://github.com/rust-lang/rust/pull/94270 I used the wrong NULL check for function pointers: `memory.ptr_may_be_null` is conservative even on machines that support ptr-to-int casts, leading to false errors in Miri. This fixes that problem, and also replaces that foot-fun of a method with `scalar_may_be_null` which is never unnecessarily conservative. r? `@oli-obk`
Diffstat (limited to 'compiler/rustc_const_eval/src/const_eval')
| -rw-r--r-- | compiler/rustc_const_eval/src/const_eval/machine.rs | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/compiler/rustc_const_eval/src/const_eval/machine.rs b/compiler/rustc_const_eval/src/const_eval/machine.rs index b2019ce40c3..99888992bc8 100644 --- a/compiler/rustc_const_eval/src/const_eval/machine.rs +++ b/compiler/rustc_const_eval/src/const_eval/machine.rs @@ -217,8 +217,9 @@ impl<'mir, 'tcx: 'mir> CompileTimeEvalContext<'mir, 'tcx> { // 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), Scalar::Ptr(ptr, _)) | (Scalar::Ptr(ptr, _), Scalar::Int(int)) => { - int.is_null() && !self.memory.ptr_may_be_null(ptr.into()) + (Scalar::Int(int), ptr @ Scalar::Ptr(..)) + | (ptr @ Scalar::Ptr(..), Scalar::Int(int)) => { + int.is_null() && !self.scalar_may_be_null(ptr) } // FIXME: return `true` for at least some comparisons where we can reliably // determine the result of runtime inequality tests at compile-time. |
