From 807f4d7e7c25b9f5584e0f82ad3601a872eacd45 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Tue, 22 Aug 2023 19:29:43 +0200 Subject: [PATCH] explain place alignment --- src/behavior-considered-undefined.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/behavior-considered-undefined.md b/src/behavior-considered-undefined.md index 855d89f7c..8819912ea 100644 --- a/src/behavior-considered-undefined.md +++ b/src/behavior-considered-undefined.md @@ -23,7 +23,7 @@ code. * Data races. -* Accessing (loading from or storing to) a place that is [dangling] or unaligned. +* Accessing (loading from or storing to) a place that is [dangling] or [unaligned]. * Performing a place projection that violates the requirements of [in-bounds pointer arithmetic][offset]. A place projection is a [field 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" 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`). +### Unaligned places +[unaligned]: #unaligned-places + +The alignment requirement of a place is computed based on the entire place expression since the last `*` (if any). +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*. +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. + ### Dangling pointers [dangling]: #dangling-pointers