diff --git a/src/inline-assembly.md b/src/inline-assembly.md index 8f7e535520..503e748c29 100644 --- a/src/inline-assembly.md +++ b/src/inline-assembly.md @@ -1567,6 +1567,9 @@ extern "sysv64-unwind" fn may_panic() { r[asm.validity] ### Correctness and validity +r[asm.validity.unsafe] +Using `asm!` requires `unsafe`, and the programmer is responsible for ensuring that the assembly code is correct and valid. + r[asm.validity.necessary-but-not-sufficient] In addition to all of the previous rules, the string argument to `asm!` must ultimately become---after all other arguments are evaluated, formatting is performed, and operands are translated---assembly that is both syntactically correct and semantically valid for the target architecture. The formatting rules allow the compiler to generate assembly with correct syntax. Rules concerning operands permit valid translation of Rust operands into and out of the assembly code. Adherence to these rules is necessary, but not sufficient, for the final expanded assembly to be both correct and valid. For instance: diff --git a/src/unsafety.md b/src/unsafety.md index 2e3be72280..56123b529f 100644 --- a/src/unsafety.md +++ b/src/unsafety.md @@ -31,6 +31,9 @@ r[safety.unsafe-extern] r[safety.unsafe-attribute] - Applying an [unsafe attribute] to an item. +r[safety.unsafe-asm] +- Using the [`asm!`] macro. + [^extern-2024]: Prior to the 2024 edition, extern blocks were allowed to be declared without `unsafe`. [`extern`]: items/external-blocks.md @@ -40,3 +43,4 @@ r[safety.unsafe-attribute] [raw pointer]: types/pointer.md [unsafe trait]: items/traits.md#unsafe-traits [unsafe attribute]: attributes.md +[`asm!`]: inline-assembly.md