Skip to content

Commit 49a9c8c

Browse files
authored
Merge pull request #1750 from RalfJung/ub-is-ours-to-define
do not reference LLVM in our definition of UB
2 parents c21d158 + 80e4268 commit 49a9c8c

File tree

1 file changed

+12
-19
lines changed

1 file changed

+12
-19
lines changed

src/behavior-considered-undefined.md

+12-19
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,18 @@ r[undefined.place-projection]
3434
[array/slice index expression][project-slice].
3535

3636
r[undefined.alias]
37-
* Breaking the [pointer aliasing rules]. `Box<T>`, `&mut T` and `&T` follow
38-
LLVM’s scoped [noalias] model, except if the `&T` contains an
39-
[`UnsafeCell<U>`]. References and boxes must not be [dangling] while they are
40-
live. The exact liveness duration is not specified, but some bounds exist:
37+
* Breaking the pointer aliasing rules. The exact aliasing rules are not determined yet, but here is an outline of the general principles:
38+
`&T` must point to memory that is not mutated while they are live (except for data inside an [`UnsafeCell<U>`]),
39+
and `&mut T` must point to memory that is not read or written by any pointer not derived from the reference and that no other reference points to while they are live.
40+
`Box<T>` is treated similar to `&'static mut T` for the purpose of these rules.
41+
The exact liveness duration is not specified, but some bounds exist:
4142
* For references, the liveness duration is upper-bounded by the syntactic
42-
lifetime assigned by the borrow checker; it cannot be live any *longer* than
43-
that lifetime.
44-
* Each time a reference or box is passed to or returned from a function, it is
45-
considered live.
46-
* When a reference (but not a `Box`!) is passed to a function, it is live at
47-
least as long as that function call, again except if the `&T` contains an
48-
[`UnsafeCell<U>`].
49-
50-
All this also applies when values of these
51-
types are passed in a (nested) field of a compound type, but not behind
52-
pointer indirections.
43+
lifetime assigned by the borrow checker; it cannot be live any *longer* than that lifetime.
44+
* Each time a reference or box is dereferenced or reborrowed, it is considered live.
45+
* Each time a reference or box is passed to or returned from a function, it is considered live.
46+
* When a reference (but not a `Box`!) is passed to a function, it is live at least as long as that function call, again except if the `&T` contains an [`UnsafeCell<U>`].
47+
48+
All this also applies when values of these types are passed in a (nested) field of a compound type, but not behind pointer indirections.
5349

5450
r[undefined.immutable]
5551
* Mutating immutable bytes.
@@ -189,7 +185,7 @@ r[undefined.validity.never]
189185

190186
r[undefined.validity.scalar]
191187
* An integer (`i*`/`u*`), floating point value (`f*`), or raw pointer must be
192-
initialized, i.e., must not be obtained from [uninitialized memory][undef].
188+
initialized, i.e., must not be obtained from uninitialized memory.
193189

194190
r[undefined.validity.str]
195191
* A `str` value is treated like `[u8]`, i.e. it must be initialized.
@@ -236,10 +232,7 @@ reading uninitialized memory is permitted are inside `union`s and in "padding"
236232

237233
[`bool`]: types/boolean.md
238234
[`const`]: items/constant-items.md
239-
[noalias]: http://llvm.org/docs/LangRef.html#noalias
240-
[pointer aliasing rules]: http://llvm.org/docs/LangRef.html#pointer-aliasing-rules
241235
[abi]: items/external-blocks.md#abi
242-
[undef]: http://llvm.org/docs/LangRef.html#undefined-values
243236
[`target_feature`]: attributes/codegen.md#the-target_feature-attribute
244237
[`UnsafeCell<U>`]: std::cell::UnsafeCell
245238
[Rustonomicon]: ../nomicon/index.html

0 commit comments

Comments
 (0)