Skip to content

Commit e51f1b7

Browse files
committed
Keep unstable target features for asm feature checking
Inline assembly uses the target features to determine which registers are available on the current target. However it needs to be able to access unstable target features for this. Fixes #99071
1 parent 50b0025 commit e51f1b7

File tree

8 files changed

+38
-28
lines changed

8 files changed

+38
-28
lines changed

Diff for: compiler/rustc_codegen_cranelift/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ impl CodegenBackend for CraneliftCodegenBackend {
167167
}
168168
}
169169

170-
fn target_features(&self, _sess: &Session) -> Vec<rustc_span::Symbol> {
170+
fn target_features(&self, _sess: &Session, _allow_unstable: bool) -> Vec<rustc_span::Symbol> {
171171
vec![]
172172
}
173173

Diff for: compiler/rustc_codegen_gcc/src/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ impl CodegenBackend for GccCodegenBackend {
133133
)
134134
}
135135

136-
fn target_features(&self, sess: &Session) -> Vec<Symbol> {
137-
target_features(sess)
136+
fn target_features(&self, sess: &Session, allow_unstable: bool) -> Vec<Symbol> {
137+
target_features(sess, allow_unstable)
138138
}
139139
}
140140

@@ -291,12 +291,12 @@ pub fn target_cpu(sess: &Session) -> &str {
291291
}
292292
}
293293

294-
pub fn target_features(sess: &Session) -> Vec<Symbol> {
294+
pub fn target_features(sess: &Session, allow_unstable: bool) -> Vec<Symbol> {
295295
supported_target_features(sess)
296296
.iter()
297297
.filter_map(
298298
|&(feature, gate)| {
299-
if sess.is_nightly_build() || gate.is_none() { Some(feature) } else { None }
299+
if sess.is_nightly_build() || allow_unstable || gate.is_none() { Some(feature) } else { None }
300300
},
301301
)
302302
.filter(|_feature| {

Diff for: compiler/rustc_codegen_llvm/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,8 @@ impl CodegenBackend for LlvmCodegenBackend {
324324
llvm_util::print_version();
325325
}
326326

327-
fn target_features(&self, sess: &Session) -> Vec<Symbol> {
328-
target_features(sess)
327+
fn target_features(&self, sess: &Session, allow_unstable: bool) -> Vec<Symbol> {
328+
target_features(sess, allow_unstable)
329329
}
330330

331331
fn codegen_crate<'tcx>(

Diff for: compiler/rustc_codegen_llvm/src/llvm_util.rs

+21-18
Original file line numberDiff line numberDiff line change
@@ -233,26 +233,29 @@ pub fn check_tied_features(
233233

234234
// Used to generate cfg variables and apply features
235235
// Must express features in the way Rust understands them
236-
pub fn target_features(sess: &Session) -> Vec<Symbol> {
236+
pub fn target_features(sess: &Session, allow_unstable: bool) -> Vec<Symbol> {
237237
let target_machine = create_informational_target_machine(sess);
238-
let mut features: Vec<Symbol> =
239-
supported_target_features(sess)
240-
.iter()
241-
.filter_map(|&(feature, gate)| {
242-
if sess.is_nightly_build() || gate.is_none() { Some(feature) } else { None }
243-
})
244-
.filter(|feature| {
245-
// check that all features in a given smallvec are enabled
246-
for llvm_feature in to_llvm_features(sess, feature) {
247-
let cstr = SmallCStr::new(llvm_feature);
248-
if !unsafe { llvm::LLVMRustHasFeature(target_machine, cstr.as_ptr()) } {
249-
return false;
250-
}
238+
let mut features: Vec<Symbol> = supported_target_features(sess)
239+
.iter()
240+
.filter_map(|&(feature, gate)| {
241+
if sess.is_nightly_build() || allow_unstable || gate.is_none() {
242+
Some(feature)
243+
} else {
244+
None
245+
}
246+
})
247+
.filter(|feature| {
248+
// check that all features in a given smallvec are enabled
249+
for llvm_feature in to_llvm_features(sess, feature) {
250+
let cstr = SmallCStr::new(llvm_feature);
251+
if !unsafe { llvm::LLVMRustHasFeature(target_machine, cstr.as_ptr()) } {
252+
return false;
251253
}
252-
true
253-
})
254-
.map(|feature| Symbol::intern(feature))
255-
.collect();
254+
}
255+
true
256+
})
257+
.map(|feature| Symbol::intern(feature))
258+
.collect();
256259

257260
// LLVM 14 changed the ABI for i128 arguments to __float/__fix builtins on Win64
258261
// (see https://reviews.llvm.org/D110413). This unstable target feature is intended for use

Diff for: compiler/rustc_codegen_ssa/src/traits/backend.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl<'tcx, T> Backend<'tcx> for T where
5959
pub trait CodegenBackend {
6060
fn init(&self, _sess: &Session) {}
6161
fn print(&self, _req: PrintRequest, _sess: &Session) {}
62-
fn target_features(&self, _sess: &Session) -> Vec<Symbol> {
62+
fn target_features(&self, _sess: &Session, _allow_unstable: bool) -> Vec<Symbol> {
6363
vec![]
6464
}
6565
fn print_passes(&self) {}

Diff for: compiler/rustc_interface/src/util.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ pub fn add_configuration(
4848
) {
4949
let tf = sym::target_feature;
5050

51-
let target_features = codegen_backend.target_features(sess);
51+
let unstable_target_features = codegen_backend.target_features(sess, true);
52+
sess.unstable_target_features.extend(unstable_target_features.iter().cloned());
53+
54+
let target_features = codegen_backend.target_features(sess, false);
5255
sess.target_features.extend(target_features.iter().cloned());
5356

5457
cfg.extend(target_features.into_iter().map(|feat| (tf, Some(feat))));

Diff for: compiler/rustc_session/src/session.rs

+4
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,9 @@ pub struct Session {
194194

195195
/// Set of enabled features for the current target.
196196
pub target_features: FxHashSet<Symbol>,
197+
198+
/// Set of enabled features for the current target, including unstable ones.
199+
pub unstable_target_features: FxHashSet<Symbol>,
197200
}
198201

199202
pub struct PerfStats {
@@ -1341,6 +1344,7 @@ pub fn build_session(
13411344
miri_unleashed_features: Lock::new(Default::default()),
13421345
asm_arch,
13431346
target_features: FxHashSet::default(),
1347+
unstable_target_features: FxHashSet::default(),
13441348
};
13451349

13461350
validate_commandline_args_with_session_available(&sess);

Diff for: compiler/rustc_typeck/src/collect.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3198,7 +3198,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: DefId) -> CodegenFnAttrs {
31983198
/// Computes the set of target features used in a function for the purposes of
31993199
/// inline assembly.
32003200
fn asm_target_features<'tcx>(tcx: TyCtxt<'tcx>, did: DefId) -> &'tcx FxHashSet<Symbol> {
3201-
let mut target_features = tcx.sess.target_features.clone();
3201+
let mut target_features = tcx.sess.unstable_target_features.clone();
32023202
if tcx.def_kind(did).has_codegen_attrs() {
32033203
let attrs = tcx.codegen_fn_attrs(did);
32043204
target_features.extend(&attrs.target_features);

0 commit comments

Comments
 (0)