Skip to content

Commit 7657115

Browse files
authored
Update guarantees of unwinding past an extern "C" function
The current docs say it will abort, however that behavior was actually reverted in rust-lang/rust#48445 and is not what currently happens in stable.
1 parent 56a13c0 commit 7657115

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/items/functions.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,15 @@ extern "C" fn new_i32() -> i32 { 0 }
174174
let fptr: extern "C" fn() -> i32 = new_i32;
175175
```
176176

177-
Functions with an ABI that differs from `"Rust"` do not support unwinding in the
178-
exact same way that Rust does. Therefore, unwinding past the end of functions
179-
with such ABIs causes the process to abort.
177+
Functions with an ABI that differs from `"Rust"` do not support unwinding in
178+
the exact same way that Rust does. Therefore, unwinding past the end of
179+
functions with such ABIs results in undefined behavior, and will differ between
180+
platforms and compiler editions. If you cannot guarantee this will not happen,
181+
you should use [`catch_unwind`] or similar to abort the program instead if
182+
unwinding would pass through the function.
180183

181-
> **Note**: The LLVM backend of the `rustc` implementation
182-
aborts the process by executing an illegal instruction.
184+
> **Note**: Currently, in nightly `rustc` the LLVM backend aborts the process
185+
> by executing an illegal instruction. However, this is not the behavior in stable.
183186
184187
## Const functions
185188

@@ -372,3 +375,4 @@ fn foo_oof(#[some_inert_attribute] arg: u8) {
372375
[`link_section`]: ../abi.md#the-link_section-attribute
373376
[`no_mangle`]: ../abi.md#the-no_mangle-attribute
374377
[built-in attributes]: ../attributes.html#built-in-attributes-index
378+
[`catch_unwind`]: ../../std/panic/fn.catch_unwind.html

0 commit comments

Comments
 (0)