Skip to content

Commit

Permalink
Merge pull request #1050 from RalfJung/target_feature
Browse files Browse the repository at this point in the history
update UB list for safe target_feature
  • Loading branch information
ehuss authored Mar 9, 2022
2 parents 7744dfa + 2d0058a commit 724714c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
14 changes: 10 additions & 4 deletions src/attributes/codegen.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ error to specify a feature for a target architecture that the crate is not
being compiled for.

It is [undefined behavior] to call a function that is compiled with a feature
that is not supported on the current platform the code is running on.
that is not supported on the current platform the code is running on, *except*
if the platform explicitly documents this to be safe.

Functions marked with `target_feature` are not inlined into a context that
does not support the given features. The `#[inline(always)]` attribute may not
Expand All @@ -75,7 +76,8 @@ The following is a list of the available feature names.

#### `x86` or `x86_64`

This platform requires that `#[target_feature]` is only applied to [`unsafe`
Executing code with unsupported features is undefined behavior on this platform.
Hence this platform requires that `#[target_feature]` is only applied to [`unsafe`
functions][unsafe function].

Feature | Implicitly Enables | Description
Expand Down Expand Up @@ -133,8 +135,12 @@ Feature | Implicitly Enables | Description

#### `wasm32` or `wasm64`

This platform allows `#[target_feature]` to be applied to both safe and
[`unsafe` functions][unsafe function].
`#[target_feature]` may be used with both safe and
[`unsafe` functions][unsafe function] on Wasm platforms. It is impossible to
cause undefined behavior via the `#[target_feature]` attribute because
attempting to use instructions unsupported by the Wasm engine will fail at load
time without the risk of being interpreted in a way different from what the
compiler expected.

Feature | Description
------------|-------------------
Expand Down
2 changes: 1 addition & 1 deletion src/behavior-considered-undefined.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ code.
is immutable, unless that data is contained within an [`UnsafeCell<U>`].
* Invoking undefined behavior via compiler intrinsics.
* Executing code compiled with platform features that the current platform
does not support (see [`target_feature`]).
does not support (see [`target_feature`]), *except* if the platform explicitly documents this to be safe.
* Calling a function with the wrong call ABI or unwinding from a function with the wrong unwind ABI.
* Producing an invalid value, even in private fields and locals. "Producing" a
value happens any time a value is assigned to or read from a place, passed to
Expand Down

0 comments on commit 724714c

Please sign in to comment.