From df701a292ce552fddad2048cfcb6edaf90222d85 Mon Sep 17 00:00:00 2001 From: Simonas Kazlauskas Date: Fri, 24 Sep 2021 18:02:02 +0300 Subject: Querify `global_backend_features` At the very least this serves to deduplicate the diagnostics that are output about unknown target features provided via CLI. --- compiler/rustc_codegen_llvm/src/attributes.rs | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'compiler/rustc_codegen_llvm/src/attributes.rs') diff --git a/compiler/rustc_codegen_llvm/src/attributes.rs b/compiler/rustc_codegen_llvm/src/attributes.rs index 4ab6f1bd0f5..8f30f0895f4 100644 --- a/compiler/rustc_codegen_llvm/src/attributes.rs +++ b/compiler/rustc_codegen_llvm/src/attributes.rs @@ -79,13 +79,11 @@ pub fn sanitize_attrs<'ll>( } if enabled.contains(SanitizerSet::MEMTAG) { // Check to make sure the mte target feature is actually enabled. - let sess = cx.tcx.sess; - let features = llvm_util::llvm_global_features(sess).join(","); - let mte_feature_enabled = features.rfind("+mte"); - let mte_feature_disabled = features.rfind("-mte"); - - if mte_feature_enabled.is_none() || (mte_feature_disabled > mte_feature_enabled) { - sess.err("`-Zsanitizer=memtag` requires `-Ctarget-feature=+mte`"); + let features = cx.tcx.global_backend_features(()); + let mte_feature = + features.iter().map(|s| &s[..]).rfind(|n| ["+mte", "-mte"].contains(&&n[..])); + if let None | Some("-mte") = mte_feature { + cx.tcx.sess.err("`-Zsanitizer=memtag` requires `-Ctarget-feature=+mte`"); } attrs.push(llvm::AttributeKind::SanitizeMemTag.create_attr(cx.llcx)); @@ -415,10 +413,11 @@ pub fn from_fn_attrs<'ll, 'tcx>( } if !function_features.is_empty() { - let mut global_features = llvm_util::llvm_global_features(cx.tcx.sess); - global_features.extend(function_features.into_iter()); - let features = global_features.join(","); - let val = CString::new(features).unwrap(); + let global_features = cx.tcx.global_backend_features(()).iter().map(|s| &s[..]); + let val = global_features + .chain(function_features.iter().map(|s| &s[..])) + .intersperse(",") + .collect::(); to_add.push(llvm::CreateAttrStringValue(cx.llcx, cstr!("target-features"), &val)); } -- cgit 1.4.1-3-g733a5