-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Miri: relax fn ptr check #94270
Miri: relax fn ptr check #94270
Conversation
Some changes occured to the CTFE / Miri engine cc @rust-lang/miri |
9065caf
to
346b8fa
Compare
let _fn = try_validation!( | ||
self.ecx.memory.get_fn(ptr), | ||
self.path, | ||
err_ub!(DanglingIntPointer(..)) | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have tests for these two errors? At least the test you edited doesn't have them, though it tests similar things for regular references
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair point, this is a good opportunity to increase our test coverage.
@bors r+ rollup |
📌 Commit 182d335 has been approved by |
You are too quick, I just wanted to write that I added more tests... |
…askrgr Rollup of 9 pull requests Successful merges: - rust-lang#89887 (Change `char` type in debuginfo to DW_ATE_UTF) - rust-lang#94267 (Remove unused ordering derivations and bounds for `SimplifiedTypeGen`) - rust-lang#94270 (Miri: relax fn ptr check) - rust-lang#94273 (add matching doc to errorkind) - rust-lang#94283 (remove feature gate in control_flow examples) - rust-lang#94288 (Cleanup a few Decoder methods) - rust-lang#94292 (riscv32imc_esp_espidf: set max_atomic_width to 64) - rust-lang#94296 (:arrow_up: rust-analyzer) - rust-lang#94300 (Fix a typo in documentation of `array::IntoIter::new_unchecked`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Miri fn ptr check: don't use conservative null check In rust-lang#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`
As discussed in rust-lang/unsafe-code-guidelines#72 (comment), the function pointer check done by Miri is currently overeager: contrary to our usual principle of only checking rather uncontroversial validity invariants, we actually check that the pointer points to a real function.
So, this relaxes the check to what the validity invariant probably will be (and what the reference already says it is): the function pointer must be non-null, and that's it.
The check that CTFE does on the final value of a constant is unchanged -- CTFE recurses through references, so it makes some sense to also recurse through function pointers. We might still want to relax this in the future, but that would be a separate change.
r? @oli-obk