about summary refs log tree commit diff
path: root/compiler/rustc_lint/src/ptr_nulls.rs
AgeCommit message (Collapse)AuthorLines
2025-07-18fix: don't panic on volatile access to nullLuigi Sartor Piucco-3/+1
According to https://discourse.llvm.org/t/rfc-volatile-access-to-non-dereferenceable-memory-may-be-well-defined/86303/4, LLVM allows volatile operations on null and handles it correctly. This should be allowed in Rust as well, because I/O memory may be hard-coded to address 0 in some cases, like the AVR chip ATtiny1626. A test case that ensured a failure when passing null to volatile was removed, since it's now valid. Due to the addition of `maybe_is_aligned` to `ub_checks`, `maybe_is_aligned_and_not_null` was refactored to use it. docs: revise restrictions on volatile operations A distinction between usage on Rust memory vs. non-Rust memory was introduced. Documentation was reworded to explain what that means, and make explicit that: - No trapping can occur from volatile operations; - On Rust memory, all safety rules must be respected; - On Rust memory, the primary difference from regular access is that volatile always involves a memory dereference; - On Rust memory, the only data affected by an operation is the one pointed to in the argument(s) of the function; - On Rust memory, provenance follows the same rules as non-volatile access; - On non-Rust memory, any address known to not contain Rust memory is valid (including 0 and usize::MAX); - On non-Rust memory, no Rust memory may be affected (it is implicit that any other non-Rust memory may be affected, though, even if not referenced by the pointer). This should be relevant when, for example, reading register A causes a flag to change in register B, or writing to A causes B to change in some way. Everything affected mustn't be inside an allocation. - On non-Rust memory, provenance is irrelevant and a pointer with none can be used in a valid way. fix: don't lint null as UB for volatile Also remove a now-unneeded `allow` line. fix: additional wording nits
2025-03-30Uplift `clippy::invalid_null_ptr_usage` as `invalid_null_arguments`Urgau-3/+103
2025-03-30Improve explicitness of the impl of the `useless_ptr_null_checks` lintUrgau-12/+12
2024-07-29Reformat `use` declarations.Nicholas Nethercote-1/+3
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-01-23Rename `LintContext::emit_spanned_lint` as `LintContext::emit_span_lint`.Nicholas Nethercote-4/+4
2023-10-13Format all the let chains in compilerMichael Goulet-8/+13
2023-08-06Improve diagnostics and add tests for function callsest31-23/+29
2023-08-05Add #[rustc_never_returns_null_ptr]est31-1/+1
And look for it in the useless_ptr_null_checks lint
2023-08-03Also add label with original type for function pointersUrgau-1/+1
2023-08-03Also lint on cast/cast_mut and ptr::from_mut/ptr::from_refUrgau-16/+36
2023-08-01Rename incorrect_fn_null_checks to useless_ptr_null_checksUrgau-0/+126