Skip to content

Commit 600999a

Browse files
committed
ABI-required target features: warn when they are missing in base CPU (rather than silently enabling them)
1 parent 06f8ed1 commit 600999a

File tree

2 files changed

+4
-51
lines changed

2 files changed

+4
-51
lines changed

Diff for: src/gcc_util.rs

+1-49
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
use std::iter::FromIterator;
2-
31
#[cfg(feature = "master")]
42
use gccjit::Context;
53
use rustc_codegen_ssa::codegen_attrs::check_tied_features;
64
use rustc_codegen_ssa::errors::TargetFeatureDisableOrEnable;
7-
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
5+
use rustc_data_structures::fx::FxHashMap;
86
use rustc_data_structures::unord::UnordSet;
97
use rustc_session::Session;
108
use rustc_target::target_features::RUSTC_SPECIFIC_FEATURES;
@@ -45,12 +43,6 @@ pub(crate) fn global_gcc_features(sess: &Session, diagnostics: bool) -> Vec<Stri
4543
let known_features = sess.target.rust_target_features();
4644
let mut featsmap = FxHashMap::default();
4745

48-
// Ensure that all ABI-required features are enabled, and the ABI-forbidden ones
49-
// are disabled.
50-
let abi_feature_constraints = sess.target.abi_required_features();
51-
let abi_incompatible_set =
52-
FxHashSet::from_iter(abi_feature_constraints.incompatible.iter().copied());
53-
5446
// Compute implied features
5547
let mut all_rust_features = vec![];
5648
for feature in sess.opts.cg.target_feature.split(',') {
@@ -117,51 +109,11 @@ pub(crate) fn global_gcc_features(sess: &Session, diagnostics: bool) -> Vec<Stri
117109
}
118110
}
119111

120-
// Ensure that the features we enable/disable are compatible with the ABI.
121-
if enable {
122-
if abi_incompatible_set.contains(feature) {
123-
sess.dcx().emit_warn(ForbiddenCTargetFeature {
124-
feature,
125-
enabled: "enabled",
126-
reason: "this feature is incompatible with the target ABI",
127-
});
128-
}
129-
} else {
130-
// FIXME: we have to request implied features here since
131-
// negative features do not handle implied features above.
132-
for &required in abi_feature_constraints.required.iter() {
133-
let implied = sess.target.implied_target_features(std::iter::once(required));
134-
if implied.contains(feature) {
135-
sess.dcx().emit_warn(ForbiddenCTargetFeature {
136-
feature,
137-
enabled: "disabled",
138-
reason: "this feature is required by the target ABI",
139-
});
140-
}
141-
}
142-
}
143-
144112
// FIXME(nagisa): figure out how to not allocate a full hashset here.
145113
featsmap.insert(feature, enable);
146114
}
147115
}
148116

149-
// To be sure the ABI-relevant features are all in the right state, we explicitly
150-
// (un)set them here. This means if the target spec sets those features wrong,
151-
// we will silently correct them rather than silently producing wrong code.
152-
// (The target sanity check tries to catch this, but we can't know which features are
153-
// enabled in GCC by default so we can't be fully sure about that check.)
154-
// We add these at the beginning of the list so that `-Ctarget-features` can
155-
// still override it... that's unsound, but more compatible with past behavior.
156-
all_rust_features.splice(
157-
0..0,
158-
abi_feature_constraints
159-
.required
160-
.iter()
161-
.map(|&f| (true, f))
162-
.chain(abi_feature_constraints.incompatible.iter().map(|&f| (false, f))),
163-
);
164-
165117
// Translate this into GCC features.
166118
let feats =
167119
all_rust_features.iter().flat_map(|&(enable, feature)| {

Diff for: src/lib.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -493,9 +493,10 @@ fn target_features_cfg(
493493
sess.target
494494
.rust_target_features()
495495
.iter()
496-
.filter(|&&(_, gate, _)| gate.in_cfg())
497496
.filter_map(|&(feature, gate, _)| {
498-
if sess.is_nightly_build() || allow_unstable || gate.requires_nightly().is_none() {
497+
if allow_unstable
498+
|| (gate.in_cfg() && (sess.is_nightly_build() || gate.requires_nightly().is_none()))
499+
{
499500
Some(feature)
500501
} else {
501502
None

0 commit comments

Comments
 (0)