Skip to content

[LangRef] Comment on validity of volatile ops on null #139803

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

Merged
merged 1 commit into from
May 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions llvm/docs/LangRef.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3563,7 +3563,8 @@ can read and/or modify state which is not accessible via a regular load
or store in this module. Volatile operations may use addresses which do
not point to memory (like MMIO registers). This means the compiler may
not use a volatile operation to prove a non-volatile access to that
address has defined behavior.
address has defined behavior. This includes addresses typically forbidden,
such as the pointer with bit-value 0.

The allowed side-effects for volatile accesses are limited. If a
non-volatile store to a given address would be legal, a volatile
Expand Down Expand Up @@ -4272,7 +4273,10 @@ The semantics of non-zero address spaces are target-specific. Memory
access through a non-dereferenceable pointer is undefined behavior in
any address space. Pointers with the bit-value 0 are only assumed to
be non-dereferenceable in address space 0, unless the function is
marked with the ``null_pointer_is_valid`` attribute.
marked with the ``null_pointer_is_valid`` attribute. However, *volatile*
access to any non-dereferenceable address may have defined behavior
(according to the target), and in this case the attribute is not needed
even for address 0.

If an object can be proven accessible through a pointer with a
different address space, the access may be modified to use that
Expand Down
15 changes: 15 additions & 0 deletions llvm/test/CodeGen/AVR/volatile-null.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
; RUN: llc < %s -mtriple=avr | FileCheck %s

define i8 @load_volatile_null() {
; CHECK-LABEL: load_volatile_null:
; CHECK: lds r24, 0
%result = load volatile i8, ptr null
ret i8 %result
}

define void @store_volatile_null(i8 %a) {
; CHECK-LABEL: store_volatile_null:
; CHECK: sts 0, r24
store volatile i8 %a, ptr null
ret void
}