Distinguish null reference production from null pointer dereference in UB checks#158796
Conversation
|
This PR changes rustc_public cc @oli-obk, @celinval, @ouz-a, @makai410 Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt This PR changes MIR cc @oli-obk, @RalfJung, @JakobDegen, @vakaras
cc @bjorn3 Some changes occurred to the CTFE machinery |
|
|
|
Requested reviewer is already assigned to this pull request. Please choose another assignee. |
| //@ run-crash | ||
| //@ compile-flags: -C debug-assertions | ||
| //@ error-pattern: null pointer dereference occurred | ||
| //@ error-pattern: null reference formed |
There was a problem hiding this comment.
"formed" is not a verb we use for this anywhere else I think. The reference calls it "producing" an invalid value, maybe use that?
There was a problem hiding this comment.
thanks! i'll update the message to use produced to exact match the terminology.
Introduce a dedicated panic for null reference production to distinguish producing a reference from a null pointer from an actual null pointer dereference. This emits a dedicated panic message for null reference production while preserving the existing panic for actual dereferences.
|
r? saethlin |
Rollup of 13 pull requests Successful merges: - #158478 (Use correct typing mode in mir building for the next solver) - #158796 (Distinguish null reference production from null pointer dereference in UB checks) - #158821 (add regression test for late-bound type method probe ICE) - #158245 (Update the rustc_perf submodule) - #158346 (Prevent rustdoc auto-trait ICEs with `-Znext-solver=globally`) - #158536 (Instatiate binder instead of skipping when suggesting function arg error) - #158553 (Avoid infinite recursion when trying to build valtrees for self-referential consts) - #158679 (Document blocking guarantees for `std::sync`) - #158826 (Reorganize `tests/ui/issues` [19/N]) - #158860 (Delete `impl_def_id` field from `ImplHeader`) - #158867 (rewrite `Align::max_for_target` in a more obvious way) - #158878 (borrowck: Inline `free_region_constraint_info()` to simplify the code) - #158881 (Update mdbook to 0.5.4)
Rollup merge of #158796 - raushan728:issues/154044, r=saethlin Distinguish null reference production from null pointer dereference in UB checks Closes #154044 This change distinguishes null reference production from actual null pointer dereferences in the UB checks. Producing a reference from a null pointer (for example, `&*ptr`) is undefined behavior even if no memory is dereferenced. This change introduces a dedicated `AssertKind::NullReferenceConstructed` and runtime panic so these cases produce a more accurate diagnostic while preserving the existing panic for actual null pointer dereferences. Summary - Add `AssertKind::NullReferenceConstructed`. - Emit it for null reference production in the MIR null check pass. - Add `panic_null_reference_constructed` and its lang item. - Keep `NullPointerDereference` for actual dereferences. - Update the affected UI tests.
Closes #154044
This change distinguishes null reference production from actual null pointer dereferences in the UB checks.
Producing a reference from a null pointer (for example,
&*ptr) is undefined behavior even if no memory is dereferenced. This change introduces a dedicatedAssertKind::NullReferenceConstructedand runtime panic so these cases produce a more accurate diagnostic while preserving the existing panic for actual null pointer dereferences.Summary
AssertKind::NullReferenceConstructed.panic_null_reference_constructedand its lang item.NullPointerDereferencefor actual dereferences.