Skip to content

Commit 03cbf50

Browse files
Rollup merge of #116576 - eduardosm:const-eval-wasm-target-features, r=RalfJung
const-eval: allow calling functions with targat features disabled at compile time in WASM This is not unsafe on WASM, see #84988 r? `@RalfJung` Fixes #116516
2 parents fcd75cc + f9b1af6 commit 03cbf50

File tree

4 files changed

+33
-6
lines changed

4 files changed

+33
-6
lines changed

compiler/rustc_const_eval/src/interpret/terminator.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -890,11 +890,13 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
890890
}
891891

892892
fn check_fn_target_features(&self, instance: ty::Instance<'tcx>) -> InterpResult<'tcx, ()> {
893+
// Calling functions with `#[target_feature]` is not unsafe on WASM, see #84988
893894
let attrs = self.tcx.codegen_fn_attrs(instance.def_id());
894-
if attrs
895-
.target_features
896-
.iter()
897-
.any(|feature| !self.tcx.sess.target_features.contains(feature))
895+
if !self.tcx.sess.target.is_like_wasm
896+
&& attrs
897+
.target_features
898+
.iter()
899+
.any(|feature| !self.tcx.sess.target_features.contains(feature))
898900
{
899901
throw_ub_custom!(
900902
fluent::const_eval_unavailable_target_features_for_fn,

src/tools/miri/ci.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ case $HOST_TARGET in
110110
MIRI_TEST_TARGET=i686-pc-windows-gnu run_tests
111111
MIRI_TEST_TARGET=x86_64-unknown-freebsd run_tests_minimal hello integer vec panic/panic concurrency/simple atomic data_race env/var
112112
MIRI_TEST_TARGET=aarch64-linux-android run_tests_minimal hello integer vec panic/panic
113-
MIRI_TEST_TARGET=wasm32-wasi run_tests_minimal no_std integer strings
114-
MIRI_TEST_TARGET=wasm32-unknown-unknown run_tests_minimal no_std integer strings
113+
MIRI_TEST_TARGET=wasm32-wasi run_tests_minimal no_std integer strings wasm
114+
MIRI_TEST_TARGET=wasm32-unknown-unknown run_tests_minimal no_std integer strings wasm
115115
MIRI_TEST_TARGET=thumbv7em-none-eabihf run_tests_minimal no_std # no_std embedded architecture
116116
MIRI_TEST_TARGET=tests/avr.json MIRI_NO_STD=1 run_tests_minimal no_std # JSON target file
117117
;;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//@only-target-wasm32: tests WASM-specific behavior
2+
//@compile-flags: -C target-feature=-simd128
3+
4+
fn main() {
5+
// Calling functions with `#[target_feature]` is not unsound on WASM, see #84988
6+
assert!(!cfg!(target_feature = "simd128"));
7+
simd128_fn();
8+
}
9+
10+
#[target_feature(enable = "simd128")]
11+
fn simd128_fn() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// only-wasm32
2+
// compile-flags:-C target-feature=-simd128
3+
// build-pass
4+
5+
#![crate_type = "lib"]
6+
7+
#[cfg(target_feature = "simd128")]
8+
compile_error!("simd128 target feature should be disabled");
9+
10+
// Calling functions with `#[target_feature]` is not unsound on WASM, see #84988
11+
const A: () = simd128_fn();
12+
13+
#[target_feature(enable = "simd128")]
14+
const fn simd128_fn() {}

0 commit comments

Comments
 (0)