rust/tests/ui/precondition-checks
Matthias Krüger 6d7d366fd3
Rollup merge of #141260 - LuigiPiucco:volatile-null, r=RalfJung
Allow volatile access to non-Rust memory, including address 0

This PR relaxes the `ub_check` in the `read_volatile`/`write_volatile` pointer operations to allow passing null. This is needed to support processors which hard-code peripheral registers on address 0, like the AVR chip ATtiny1626. LLVM understands this as valid and handles it correctly, as tested in my [PR to add a note about it](https://github.com/llvm/llvm-project/pull/139803/commits/6387c82255c56d3035d249eb54110695e76b8030#diff-81bbb96298c32fa901beb82ab3b97add27a410c01d577c1f8c01000ed2055826) (rustc generates the same LLVM IR as expected there when this PR is applied, and consequently the same AVR assembly).

Follow-up and implementation of the discussions in:
- https://internals.rust-lang.org/t/pre-rfc-conditionally-supported-volatile-access-to-address-0/12881/7
- https://github.com/Rahix/avr-device/pull/185;
- [#t-lang > Adding the possibility of volatile access to address 0](https://rust-lang.zulipchat.com/#narrow/channel/213817-t-lang/topic/Adding.20the.20possibility.20of.20volatile.20access.20to.20address.200/with/513303502)
- https://discourse.llvm.org/t/rfc-volatile-access-to-non-dereferenceable-memory-may-be-well-defined/86303

r? ````@RalfJung````

Also fixes https://github.com/rust-lang/unsafe-code-guidelines/issues/29 (about as good as it'll get, null will likely never be a "normal" address in Rust)
2025-07-20 08:56:05 +02:00
..
alignment.rs tests: Require run-fail ui tests to have an exit code (SIGABRT not ok) 2025-07-19 18:44:07 +02:00
ascii-char-digit_unchecked.rs tests: Require run-fail ui tests to have an exit code (SIGABRT not ok) 2025-07-19 18:44:07 +02:00
assert_unchecked.rs tests: Require run-fail ui tests to have an exit code (SIGABRT not ok) 2025-07-19 18:44:07 +02:00
cfg-ub-checks-default.rs Fix revisions syntax 2024-04-11 17:53:27 -04:00
cfg-ub-checks-no.rs Put checks that detect UB under their own flag below debug_assertions 2024-04-06 11:21:47 -04:00
cfg-ub-checks-yes.rs Put checks that detect UB under their own flag below debug_assertions 2024-04-06 11:21:47 -04:00
char-from_u32_unchecked.rs tests: Require run-fail ui tests to have an exit code (SIGABRT not ok) 2025-07-19 18:44:07 +02:00
copy-nonoverlapping.rs tests: Require run-fail ui tests to have an exit code (SIGABRT not ok) 2025-07-19 18:44:07 +02:00
copy.rs tests: Require run-fail ui tests to have an exit code (SIGABRT not ok) 2025-07-19 18:44:07 +02:00
layout.rs tests: Require run-fail ui tests to have an exit code (SIGABRT not ok) 2025-07-19 18:44:07 +02:00
nonnull.rs tests: Require run-fail ui tests to have an exit code (SIGABRT not ok) 2025-07-19 18:44:07 +02:00
nonzero-from_mut_unchecked.rs tests: Require run-fail ui tests to have an exit code (SIGABRT not ok) 2025-07-19 18:44:07 +02:00
nonzero-new_unchecked.rs tests: Require run-fail ui tests to have an exit code (SIGABRT not ok) 2025-07-19 18:44:07 +02:00
read.rs tests: ensure disabled tests have a reason 2025-04-12 15:24:25 +08:00
read_volatile.rs Rollup merge of #141260 - LuigiPiucco:volatile-null, r=RalfJung 2025-07-20 08:56:05 +02:00
replace.rs tests: Require run-fail ui tests to have an exit code (SIGABRT not ok) 2025-07-19 18:44:07 +02:00
slice-from-raw-parts-mut.rs tests: Require run-fail ui tests to have an exit code (SIGABRT not ok) 2025-07-19 18:44:07 +02:00
slice-from-raw-parts.rs tests: Require run-fail ui tests to have an exit code (SIGABRT not ok) 2025-07-19 18:44:07 +02:00
slice-get_unchecked.rs tests: Require run-fail ui tests to have an exit code (SIGABRT not ok) 2025-07-19 18:44:07 +02:00
slice-get_unchecked_mut.rs tests: Require run-fail ui tests to have an exit code (SIGABRT not ok) 2025-07-19 18:44:07 +02:00
slice-swap_unchecked.rs Add more precondition check tests 2024-10-09 19:34:27 -04:00
str-get_unchecked.rs tests: Require run-fail ui tests to have an exit code (SIGABRT not ok) 2025-07-19 18:44:07 +02:00
str-get_unchecked_mut.rs tests: Require run-fail ui tests to have an exit code (SIGABRT not ok) 2025-07-19 18:44:07 +02:00
swap-nonoverlapping.rs tests: Require run-fail ui tests to have an exit code (SIGABRT not ok) 2025-07-19 18:44:07 +02:00
unchecked_add.rs tests: Require run-fail ui tests to have an exit code (SIGABRT not ok) 2025-07-19 18:44:07 +02:00
unchecked_mul.rs tests: Require run-fail ui tests to have an exit code (SIGABRT not ok) 2025-07-19 18:44:07 +02:00
unchecked_shl.rs tests: Require run-fail ui tests to have an exit code (SIGABRT not ok) 2025-07-19 18:44:07 +02:00
unchecked_shr.rs tests: Require run-fail ui tests to have an exit code (SIGABRT not ok) 2025-07-19 18:44:07 +02:00
unchecked_sub.rs tests: Require run-fail ui tests to have an exit code (SIGABRT not ok) 2025-07-19 18:44:07 +02:00
unreachable_unchecked.rs tests: Require run-fail ui tests to have an exit code (SIGABRT not ok) 2025-07-19 18:44:07 +02:00
vec-from-parts.rs tests: Require run-fail ui tests to have an exit code (SIGABRT not ok) 2025-07-19 18:44:07 +02:00
vec-from-raw-parts.rs tests: Require run-fail ui tests to have an exit code (SIGABRT not ok) 2025-07-19 18:44:07 +02:00
vec-set-len.rs tests: Require run-fail ui tests to have an exit code (SIGABRT not ok) 2025-07-19 18:44:07 +02:00
write.rs tests: ensure disabled tests have a reason 2025-04-12 15:24:25 +08:00
write_bytes.rs tests: ensure disabled tests have a reason 2025-04-12 15:24:25 +08:00
write_volatile.rs Rollup merge of #141260 - LuigiPiucco:volatile-null, r=RalfJung 2025-07-20 08:56:05 +02:00
zero-size-null.rs Allow invalid_null_arguments in some tests 2025-03-30 19:33:15 +02:00