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
This commit is contained in:
parent
50b00252ae
commit
e51f1b7e27
@ -167,7 +167,7 @@ fn init(&self, sess: &Session) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn target_features(&self, _sess: &Session) -> Vec<rustc_span::Symbol> {
|
fn target_features(&self, _sess: &Session, _allow_unstable: bool) -> Vec<rustc_span::Symbol> {
|
||||||
vec![]
|
vec![]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,8 +133,8 @@ fn link(&self, sess: &Session, codegen_results: CodegenResults, outputs: &Output
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn target_features(&self, sess: &Session) -> Vec<Symbol> {
|
fn target_features(&self, sess: &Session, allow_unstable: bool) -> Vec<Symbol> {
|
||||||
target_features(sess)
|
target_features(sess, allow_unstable)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -291,12 +291,12 @@ pub fn target_cpu(sess: &Session) -> &str {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn target_features(sess: &Session) -> Vec<Symbol> {
|
pub fn target_features(sess: &Session, allow_unstable: bool) -> Vec<Symbol> {
|
||||||
supported_target_features(sess)
|
supported_target_features(sess)
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(
|
.filter_map(
|
||||||
|&(feature, gate)| {
|
|&(feature, gate)| {
|
||||||
if sess.is_nightly_build() || gate.is_none() { Some(feature) } else { None }
|
if sess.is_nightly_build() || allow_unstable || gate.is_none() { Some(feature) } else { None }
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.filter(|_feature| {
|
.filter(|_feature| {
|
||||||
|
@ -324,8 +324,8 @@ fn print_version(&self) {
|
|||||||
llvm_util::print_version();
|
llvm_util::print_version();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn target_features(&self, sess: &Session) -> Vec<Symbol> {
|
fn target_features(&self, sess: &Session, allow_unstable: bool) -> Vec<Symbol> {
|
||||||
target_features(sess)
|
target_features(sess, allow_unstable)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn codegen_crate<'tcx>(
|
fn codegen_crate<'tcx>(
|
||||||
|
@ -233,26 +233,29 @@ pub fn check_tied_features(
|
|||||||
|
|
||||||
// Used to generate cfg variables and apply features
|
// Used to generate cfg variables and apply features
|
||||||
// Must express features in the way Rust understands them
|
// Must express features in the way Rust understands them
|
||||||
pub fn target_features(sess: &Session) -> Vec<Symbol> {
|
pub fn target_features(sess: &Session, allow_unstable: bool) -> Vec<Symbol> {
|
||||||
let target_machine = create_informational_target_machine(sess);
|
let target_machine = create_informational_target_machine(sess);
|
||||||
let mut features: Vec<Symbol> =
|
let mut features: Vec<Symbol> = supported_target_features(sess)
|
||||||
supported_target_features(sess)
|
.iter()
|
||||||
.iter()
|
.filter_map(|&(feature, gate)| {
|
||||||
.filter_map(|&(feature, gate)| {
|
if sess.is_nightly_build() || allow_unstable || gate.is_none() {
|
||||||
if sess.is_nightly_build() || gate.is_none() { Some(feature) } else { None }
|
Some(feature)
|
||||||
})
|
} else {
|
||||||
.filter(|feature| {
|
None
|
||||||
// check that all features in a given smallvec are enabled
|
}
|
||||||
for llvm_feature in to_llvm_features(sess, feature) {
|
})
|
||||||
let cstr = SmallCStr::new(llvm_feature);
|
.filter(|feature| {
|
||||||
if !unsafe { llvm::LLVMRustHasFeature(target_machine, cstr.as_ptr()) } {
|
// check that all features in a given smallvec are enabled
|
||||||
return false;
|
for llvm_feature in to_llvm_features(sess, feature) {
|
||||||
}
|
let cstr = SmallCStr::new(llvm_feature);
|
||||||
|
if !unsafe { llvm::LLVMRustHasFeature(target_machine, cstr.as_ptr()) } {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
true
|
}
|
||||||
})
|
true
|
||||||
.map(|feature| Symbol::intern(feature))
|
})
|
||||||
.collect();
|
.map(|feature| Symbol::intern(feature))
|
||||||
|
.collect();
|
||||||
|
|
||||||
// LLVM 14 changed the ABI for i128 arguments to __float/__fix builtins on Win64
|
// LLVM 14 changed the ABI for i128 arguments to __float/__fix builtins on Win64
|
||||||
// (see https://reviews.llvm.org/D110413). This unstable target feature is intended for use
|
// (see https://reviews.llvm.org/D110413). This unstable target feature is intended for use
|
||||||
|
@ -59,7 +59,7 @@ impl<'tcx, T> Backend<'tcx> for T where
|
|||||||
pub trait CodegenBackend {
|
pub trait CodegenBackend {
|
||||||
fn init(&self, _sess: &Session) {}
|
fn init(&self, _sess: &Session) {}
|
||||||
fn print(&self, _req: PrintRequest, _sess: &Session) {}
|
fn print(&self, _req: PrintRequest, _sess: &Session) {}
|
||||||
fn target_features(&self, _sess: &Session) -> Vec<Symbol> {
|
fn target_features(&self, _sess: &Session, _allow_unstable: bool) -> Vec<Symbol> {
|
||||||
vec![]
|
vec![]
|
||||||
}
|
}
|
||||||
fn print_passes(&self) {}
|
fn print_passes(&self) {}
|
||||||
|
@ -48,7 +48,10 @@ pub fn add_configuration(
|
|||||||
) {
|
) {
|
||||||
let tf = sym::target_feature;
|
let tf = sym::target_feature;
|
||||||
|
|
||||||
let target_features = codegen_backend.target_features(sess);
|
let unstable_target_features = codegen_backend.target_features(sess, true);
|
||||||
|
sess.unstable_target_features.extend(unstable_target_features.iter().cloned());
|
||||||
|
|
||||||
|
let target_features = codegen_backend.target_features(sess, false);
|
||||||
sess.target_features.extend(target_features.iter().cloned());
|
sess.target_features.extend(target_features.iter().cloned());
|
||||||
|
|
||||||
cfg.extend(target_features.into_iter().map(|feat| (tf, Some(feat))));
|
cfg.extend(target_features.into_iter().map(|feat| (tf, Some(feat))));
|
||||||
|
@ -194,6 +194,9 @@ pub struct Session {
|
|||||||
|
|
||||||
/// Set of enabled features for the current target.
|
/// Set of enabled features for the current target.
|
||||||
pub target_features: FxHashSet<Symbol>,
|
pub target_features: FxHashSet<Symbol>,
|
||||||
|
|
||||||
|
/// Set of enabled features for the current target, including unstable ones.
|
||||||
|
pub unstable_target_features: FxHashSet<Symbol>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct PerfStats {
|
pub struct PerfStats {
|
||||||
@ -1341,6 +1344,7 @@ pub fn build_session(
|
|||||||
miri_unleashed_features: Lock::new(Default::default()),
|
miri_unleashed_features: Lock::new(Default::default()),
|
||||||
asm_arch,
|
asm_arch,
|
||||||
target_features: FxHashSet::default(),
|
target_features: FxHashSet::default(),
|
||||||
|
unstable_target_features: FxHashSet::default(),
|
||||||
};
|
};
|
||||||
|
|
||||||
validate_commandline_args_with_session_available(&sess);
|
validate_commandline_args_with_session_available(&sess);
|
||||||
|
@ -3198,7 +3198,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: DefId) -> CodegenFnAttrs {
|
|||||||
/// Computes the set of target features used in a function for the purposes of
|
/// Computes the set of target features used in a function for the purposes of
|
||||||
/// inline assembly.
|
/// inline assembly.
|
||||||
fn asm_target_features<'tcx>(tcx: TyCtxt<'tcx>, did: DefId) -> &'tcx FxHashSet<Symbol> {
|
fn asm_target_features<'tcx>(tcx: TyCtxt<'tcx>, did: DefId) -> &'tcx FxHashSet<Symbol> {
|
||||||
let mut target_features = tcx.sess.target_features.clone();
|
let mut target_features = tcx.sess.unstable_target_features.clone();
|
||||||
if tcx.def_kind(did).has_codegen_attrs() {
|
if tcx.def_kind(did).has_codegen_attrs() {
|
||||||
let attrs = tcx.codegen_fn_attrs(did);
|
let attrs = tcx.codegen_fn_attrs(did);
|
||||||
target_features.extend(&attrs.target_features);
|
target_features.extend(&attrs.target_features);
|
||||||
|
Loading…
Reference in New Issue
Block a user