Skip to content

Commit 7fe82b1

Browse files
committed
Change wording on return_address!() to be clear that returning a null pointer is best-effort.
1 parent 336e40e commit 7fe82b1

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

library/core/src/arch.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,14 @@ pub fn breakpoint() {
7777
core::intrinsics::breakpoint();
7878
}
7979

80-
/// The `core::arch::return_address!()` macro returns a pointer with an address that corresponds to the caller of the function that invoked the `return_address!()` macro, or a null pointer if it cannot be determined. The pointer has no provenance, as if created by `core::ptr::without_provenance`. It cannot be used to read memory (other than ZSTs).
80+
/// The `core::arch::return_address!()` macro returns a pointer with an address that corresponds to the caller of the function that invoked the `return_address!()` macro.
81+
/// The pointer has no provenance, as if created by `core::ptr::without_provenance`. It cannot be used to read memory (other than ZSTs).
8182
///
82-
/// The value returned by the macro depends highly on the architecture and compiler (including any options set). In particular, it is allowed to be wrong (particularly if inlining is involved), or even contain a nonsense value. The result of this macro must not be relied upon for soundness or correctness, only for debugging purposes.
83+
/// The value returned by the macro depends highly on the architecture and compiler (including any options set).
84+
/// In particular, it is allowed to be wrong (particularly if inlining is involved), or even contain a nonsense value.
85+
/// The result of this macro must not be relied upon for soundness or correctness, only for debugging purposes.
8386
/// Formally, this function returns a pointer with a non-deterministic address and no provenance.
87+
/// As a best effort, if a useful value cannot be determined (for example, due to limitations on the current codegen), this macro tries to return a null pointer instead of nonsense (this cannot be relied upon for correctness, however).
8488
///
8589
/// This is equivalent to the gcc `__builtin_return_address(0)` intrinsic (other forms of the intrinsic are not supported). Because the operation can be always performed by the compiler without crashing or causing undefined behaviour, invoking the macro is a safe operation.
8690
///

0 commit comments

Comments
 (0)