Skip to content

Commit 807f4d7

Browse files
committed
explain place alignment
1 parent f4876d6 commit 807f4d7

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/behavior-considered-undefined.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ code.
2323
</div>
2424

2525
* Data races.
26-
* Accessing (loading from or storing to) a place that is [dangling] or unaligned.
26+
* Accessing (loading from or storing to) a place that is [dangling] or [unaligned].
2727
* Performing a place projection that violates the requirements of [in-bounds
2828
pointer arithmetic][offset]. A place projection is a [field
2929
expression][project-field], a [tuple index expression][project-tuple], or an
@@ -100,6 +100,13 @@ reading uninitialized memory is permitted are inside `union`s and in "padding"
100100

101101
The span of bytes a pointer or reference "points to" is determined by the pointer value and the size of the pointee type (using `size_of_val`).
102102

103+
### Unaligned places
104+
[unaligned]: #unaligned-places
105+
106+
The alignment requirement of a place is computed based on the entire place expression since the last `*` (if any).
107+
If the place was computed via `(*ptr).field.field`, then the final place is considered aligned only if `ptr` is aligned *according to its type*.
108+
For instance, if a field of type `u8` sits at offset 4 in an 8-aligned struct, then loading from `(*ptr).field` requires alignment 4.
109+
103110
### Dangling pointers
104111
[dangling]: #dangling-pointers
105112

0 commit comments

Comments
 (0)