-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Insert null checks for pointer dereferences when debug assertions are enabled #134424
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
Conversation
This PR changes Stable MIR cc @oli-obk, @celinval, @ouz-a This PR changes MIR cc @oli-obk, @RalfJung, @JakobDegen, @davidtwco, @celinval, @vakaras Some changes occurred to the CTFE machinery cc @rust-lang/wg-const-eval Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt Some changes occurred in compiler/rustc_codegen_cranelift cc @bjorn3 rust-analyzer is developed in its own repository. If possible, consider making this change to rust-lang/rust-analyzer instead. cc @rust-lang/rust-analyzer |
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (61e98dc): comparison URL. Overall result: no relevant changes - no action neededBenchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf. @bors rollup=never Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)Results (primary 3.0%, secondary 3.8%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResults (secondary -3.4%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeResults (primary -0.1%, secondary -0.1%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Bootstrap: 768.397s -> 772.491s (0.53%) |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
For PRs like this that change codegen, CI always tests using a stage2 build, so if you break codegen, you'll often get a CI failure while using your new compiler to build itself, which is hard to debug from. |
Is there a specific reason that this is a separate MIR pass from the null ptr check? Together they form the pointer validity checks, so I don't quite see why those would be checked separately. |
My reasoning here was that this is two separate checks that people maybe want to enable or disable separately (lets say they only like to pay the overhead for alignment and don't care about null). My thinking was that two separate MIR passes solve this problem the most straightforward way, but I am happy to discuss this. |
Similar to how the alignment is already checked, this adds a check
for null pointer dereferences in debug mode. It is implemented similarly
to the alignment check as a
MirPass
.This inserts checks in the same places as the
CheckAlignment
pass and additionallyalso inserts checks for
Borrows
, so code likewill have a check inserted on dereference. This is done because null references
are UB. The alignment check doesn't cover these places, because in
&(*ptr).field
,the exact requirement is that the final reference must be aligned. This is something to
consider further enhancements of the alignment check.
For now this is implemented as a separate
MirPass
, to make it easy to disablethis check if necessary.
This is related to a 2025H1 project goal for better UB checks in debug
mode: rust-lang/rust-project-goals#177.
r? @saethlin