Skip to content

Commit 724714c

Browse files
authored
Merge pull request rust-lang#1050 from RalfJung/target_feature
update UB list for safe target_feature
2 parents 7744dfa + 2d0058a commit 724714c

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/attributes/codegen.md

+10-4
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ error to specify a feature for a target architecture that the crate is not
6363
being compiled for.
6464

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

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

7677
#### `x86` or `x86_64`
7778

78-
This platform requires that `#[target_feature]` is only applied to [`unsafe`
79+
Executing code with unsupported features is undefined behavior on this platform.
80+
Hence this platform requires that `#[target_feature]` is only applied to [`unsafe`
7981
functions][unsafe function].
8082

8183
Feature | Implicitly Enables | Description
@@ -133,8 +135,12 @@ Feature | Implicitly Enables | Description
133135

134136
#### `wasm32` or `wasm64`
135137

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

139145
Feature | Description
140146
------------|-------------------

src/behavior-considered-undefined.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ code.
3333
is immutable, unless that data is contained within an [`UnsafeCell<U>`].
3434
* Invoking undefined behavior via compiler intrinsics.
3535
* Executing code compiled with platform features that the current platform
36-
does not support (see [`target_feature`]).
36+
does not support (see [`target_feature`]), *except* if the platform explicitly documents this to be safe.
3737
* Calling a function with the wrong call ABI or unwinding from a function with the wrong unwind ABI.
3838
* Producing an invalid value, even in private fields and locals. "Producing" a
3939
value happens any time a value is assigned to or read from a place, passed to

0 commit comments

Comments
 (0)