diff options
| author | Eduardo Sánchez Muñoz <eduardosm-dev@e64.io> | 2023-07-16 00:23:17 +0200 |
|---|---|---|
| committer | Eduardo Sánchez Muñoz <eduardosm-dev@e64.io> | 2023-07-16 00:23:17 +0200 |
| commit | b5fde0dae0af1a4a273830e695dc0aaf7c3885ba (patch) | |
| tree | 7c3e6dabf8e2eb1cc256a885eb2f767fa074cf98 /compiler/rustc_const_eval/src | |
| parent | ad963232d9b987d66a6f8e6ec4141f672b8b9900 (diff) | |
| download | rust-b5fde0dae0af1a4a273830e695dc0aaf7c3885ba.tar.gz rust-b5fde0dae0af1a4a273830e695dc0aaf7c3885ba.zip | |
miri: fail when calling a function that requires an unavailable target feature
miri will report an UB when calling a function that has a `#[target_feature(enable = ...)]` attribute is called and the required feature is not available. "Available features" are the same that `is_x86_feature_detected!` (or equivalent) reports to be available during miri execution (which can be enabled or disabled with the `-C target-feature` flag).
Diffstat (limited to 'compiler/rustc_const_eval/src')
| -rw-r--r-- | compiler/rustc_const_eval/src/interpret/terminator.rs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/compiler/rustc_const_eval/src/interpret/terminator.rs b/compiler/rustc_const_eval/src/interpret/terminator.rs index c944782b487..b6eea191aa6 100644 --- a/compiler/rustc_const_eval/src/interpret/terminator.rs +++ b/compiler/rustc_const_eval/src/interpret/terminator.rs @@ -503,6 +503,25 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { } } + let attrs = self.tcx.codegen_fn_attrs(instance.def_id()); + let missing_features: Vec<_> = attrs + .target_features + .iter() + .copied() + .filter(|feature| !self.tcx.sess.target_features.contains(feature)) + .collect(); + if !missing_features.is_empty() { + let mut missing_features_str = String::from(missing_features[0].as_str()); + for missing_feature in missing_features[1..].iter() { + missing_features_str.push(','); + missing_features_str.push_str(missing_feature.as_str()); + } + throw_ub_custom!( + fluent::const_eval_unavailable_target_features_for_fn, + unavailable_feats = missing_features_str, + ); + } + if !callee_fn_abi.can_unwind { // The callee cannot unwind, so force the `Unreachable` unwind handling. unwind = mir::UnwindAction::Unreachable; |
