Skip to content

Commit 4645e6a

Browse files
committed
Auto merge of #3851 - rust-lang:rustup-2024-08-29, r=RalfJung
Automatic Rustup
2 parents d1aa077 + 728a273 commit 4645e6a

18 files changed

+81
-30
lines changed

rust-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
d9a2cc4daee38c63b2f69710ed61d40acc32b709
1+
acb4e8b6251f1d8da36f08e7a70fa23fc581839e

src/machine.rs

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -946,16 +946,48 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> {
946946
ecx.machine.validation == ValidationMode::Deep
947947
}
948948

949-
#[inline(always)]
950-
fn enforce_abi(_ecx: &MiriInterpCx<'tcx>) -> bool {
951-
true
952-
}
953-
954949
#[inline(always)]
955950
fn ignore_optional_overflow_checks(ecx: &MiriInterpCx<'tcx>) -> bool {
956951
!ecx.tcx.sess.overflow_checks()
957952
}
958953

954+
fn check_fn_target_features(
955+
ecx: &MiriInterpCx<'tcx>,
956+
instance: ty::Instance<'tcx>,
957+
) -> InterpResult<'tcx> {
958+
let attrs = ecx.tcx.codegen_fn_attrs(instance.def_id());
959+
if attrs
960+
.target_features
961+
.iter()
962+
.any(|feature| !ecx.tcx.sess.target_features.contains(&feature.name))
963+
{
964+
let unavailable = attrs
965+
.target_features
966+
.iter()
967+
.filter(|&feature| {
968+
!feature.implied && !ecx.tcx.sess.target_features.contains(&feature.name)
969+
})
970+
.fold(String::new(), |mut s, feature| {
971+
if !s.is_empty() {
972+
s.push_str(", ");
973+
}
974+
s.push_str(feature.name.as_str());
975+
s
976+
});
977+
let msg = format!(
978+
"calling a function that requires unavailable target features: {unavailable}"
979+
);
980+
// On WASM, this is not UB, but instead gets rejected during validation of the module
981+
// (see #84988).
982+
if ecx.tcx.sess.target.is_like_wasm {
983+
throw_machine_stop!(TerminationInfo::Abort(msg));
984+
} else {
985+
throw_ub_format!("{msg}");
986+
}
987+
}
988+
Ok(())
989+
}
990+
959991
#[inline(always)]
960992
fn find_mir_or_eval_fn(
961993
ecx: &mut MiriInterpCx<'tcx>,
@@ -1060,6 +1092,10 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> {
10601092
ecx.generate_nan(inputs)
10611093
}
10621094

1095+
fn ub_checks(ecx: &InterpCx<'tcx, Self>) -> InterpResult<'tcx, bool> {
1096+
Ok(ecx.tcx.sess.ub_checks())
1097+
}
1098+
10631099
fn thread_local_static_pointer(
10641100
ecx: &mut MiriInterpCx<'tcx>,
10651101
def_id: DefId,
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//@only-target-wasm: 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+
// But if the compiler actually uses the target feature, it will lead to an error when the module is loaded.
7+
// We emulate this with an "unsupported" error.
8+
assert!(!cfg!(target_feature = "simd128"));
9+
simd128_fn(); //~ERROR: unavailable target features
10+
}
11+
12+
#[target_feature(enable = "simd128")]
13+
fn simd128_fn() {}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error: abnormal termination: calling a function that requires unavailable target features: simd128
2+
--> $DIR/target_feature_wasm.rs:LL:CC
3+
|
4+
LL | simd128_fn();
5+
| ^^^^^^^^^^^^ calling a function that requires unavailable target features: simd128
6+
|
7+
= note: BACKTRACE:
8+
= note: inside `main` at $DIR/target_feature_wasm.rs:LL:CC
9+
10+
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
11+
12+
error: aborting due to 1 previous error
13+

tests/fail/intrinsics/intrinsic_target_feature.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//@ignore-target-avr
88
//@ignore-target-s390x
99
//@ignore-target-thumbv7em
10-
//@ignore-target-wasm32
10+
//@ignore-target-wasm
1111
// Explicitly disable SSE4.1 because it is enabled by default on macOS
1212
//@compile-flags: -C target-feature=-sse4.1
1313

tests/pass/function_calls/target_feature_wasm.rs

Lines changed: 0 additions & 11 deletions
This file was deleted.

tests/pass/shims/x86/intrinsics-sha.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//@ignore-target-avr
77
//@ignore-target-s390x
88
//@ignore-target-thumbv7em
9-
//@ignore-target-wasm32
9+
//@ignore-target-wasm
1010
//@compile-flags: -C target-feature=+sha,+sse2,+ssse3,+sse4.1
1111

1212
#[cfg(target_arch = "x86")]

tests/pass/shims/x86/intrinsics-x86-adx.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//@ignore-target-avr
77
//@ignore-target-s390x
88
//@ignore-target-thumbv7em
9-
//@ignore-target-wasm32
9+
//@ignore-target-wasm
1010
//@compile-flags: -C target-feature=+adx
1111

1212
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]

tests/pass/shims/x86/intrinsics-x86-aes-vaes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//@ignore-target-avr
77
//@ignore-target-s390x
88
//@ignore-target-thumbv7em
9-
//@ignore-target-wasm32
9+
//@ignore-target-wasm
1010
//@compile-flags: -C target-feature=+aes,+vaes,+avx512f
1111

1212
#![feature(avx512_target_feature, stdarch_x86_avx512)]

tests/pass/shims/x86/intrinsics-x86-avx.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//@ignore-target-avr
77
//@ignore-target-s390x
88
//@ignore-target-thumbv7em
9-
//@ignore-target-wasm32
9+
//@ignore-target-wasm
1010
//@compile-flags: -C target-feature=+avx
1111

1212
#[cfg(target_arch = "x86")]

0 commit comments

Comments
 (0)