Skip to content

Commit ad0c048

Browse files
committed
Auto merge of #129691 - matthiaskrgr:rollup-owlcr3m, r=matthiaskrgr
Rollup of 11 pull requests Successful merges: - #129421 (add repr to the allowlist for naked functions) - #129480 (docs: correct panic conditions for rem_euclid and similar functions) - #129551 (ub_checks intrinsics: fall back to cfg(ub_checks)) - #129608 (const-eval: do not make UbChecks behavior depend on current crate's flags) - #129613 (interpret: do not make const-eval query result depend on tcx.sess) - #129641 (rustdoc: fix missing resource suffix on `crates.js`) - #129657 (Rename `BikeshedIntrinsicFrom` to `TransmuteFrom`) - #129666 (interpret: add missing alignment check in raw_eq) - #129667 (Rustc driver cleanup) - #129668 (Fix Pin::set bounds regression) - #129686 (coverage: Rename `CodeRegion` to `SourceRegion`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 100da5c + 2823479 commit ad0c048

File tree

2 files changed

+44
-6
lines changed

2 files changed

+44
-6
lines changed

src/machine.rs

+41-5
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,

tests/pass/function_calls/target_feature_wasm.rs renamed to tests/panic/target_feature_wasm.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
//@compile-flags: -C target-feature=-simd128
33

44
fn main() {
5-
// Calling functions with `#[target_feature]` is not unsound on WASM, see #84988
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.
68
assert!(!cfg!(target_feature = "simd128"));
79
simd128_fn();
810
}

0 commit comments

Comments
 (0)