Port MissingFeatures and TargetFeatureDisableOrEnable

This commit is contained in:
SLASHLogin 2022-08-26 21:27:17 +02:00
parent 33ef16f291
commit 185ef7b6de
4 changed files with 45 additions and 14 deletions

View File

@ -12,7 +12,7 @@
use smallvec::SmallVec;
use crate::attributes;
use crate::errors::SanitizerMemtagRequiresMte;
use crate::errors::{MissingFeatures, SanitizerMemtagRequiresMte, TargetFeatureDisableOrEnable};
use crate::llvm::AttributePlace::Function;
use crate::llvm::{self, AllocKindFlags, Attribute, AttributeKind, AttributePlace, MemoryEffects};
use crate::llvm_util;
@ -394,13 +394,11 @@ pub fn from_fn_attrs<'ll, 'tcx>(
.get_attrs(instance.def_id(), sym::target_feature)
.next()
.map_or_else(|| cx.tcx.def_span(instance.def_id()), |a| a.span);
let msg = format!(
"the target features {} must all be either enabled or disabled together",
f.join(", ")
);
let mut err = cx.tcx.sess.struct_span_err(span, &msg);
err.help("add the missing features in a `target_feature` attribute");
err.emit();
cx.tcx
.sess
.create_err(TargetFeatureDisableOrEnable { features: f, span: Some(span) })
.subdiagnostic(MissingFeatures)
.emit();
return;
}

View File

@ -2,7 +2,8 @@
use rustc_errors::fluent;
use rustc_errors::DiagnosticBuilder;
use rustc_macros::SessionDiagnostic;
use rustc_errors::ErrorGuaranteed;
use rustc_macros::{SessionDiagnostic, SessionSubdiagnostic};
use rustc_session::SessionDiagnostic;
use rustc_span::Span;
@ -117,3 +118,29 @@ pub(crate) struct DlltoolFailImportLibrary<'a> {
pub(crate) struct UnknownArchiveKind<'a> {
pub kind: &'a str,
}
pub(crate) struct TargetFeatureDisableOrEnable<'a> {
pub features: &'a [&'a str],
pub span: Option<Span>,
}
#[derive(SessionSubdiagnostic)]
#[help(codegen_llvm::missing_features)]
pub(crate) struct MissingFeatures;
impl SessionDiagnostic<'_, ErrorGuaranteed> for TargetFeatureDisableOrEnable<'_> {
fn into_diagnostic(
self,
sess: &'_ rustc_session::parse::ParseSess,
) -> DiagnosticBuilder<'_, ErrorGuaranteed> {
let mut diag = if let Some(span) = self.span {
let mut diag = sess.struct_err(fluent::codegen_llvm::target_feature_disable_or_enable);
diag.set_span(span);
diag
} else {
sess.struct_err(fluent::codegen_llvm::target_feature_disable_or_enable)
};
diag.set_arg("features", self.features.join(", "));
diag
}
}

View File

@ -1,5 +1,5 @@
use crate::back::write::create_informational_target_machine;
use crate::errors::UnknownCTargetFeature;
use crate::errors::{TargetFeatureDisableOrEnable, UnknownCTargetFeature};
use crate::llvm;
use libc::c_int;
use rustc_codegen_ssa::target_features::{
@ -480,10 +480,10 @@ pub(crate) fn global_llvm_features(sess: &Session, diagnostics: bool) -> Vec<Str
features.extend(feats);
if diagnostics && let Some(f) = check_tied_features(sess, &featsmap) {
sess.err(&format!(
"target features {} must all be enabled or disabled together",
f.join(", ")
));
sess.emit_err(TargetFeatureDisableOrEnable {
features: f,
span: None
});
}
features

View File

@ -51,3 +51,9 @@ codegen_llvm_dlltool_fail_import_library =
codegen_llvm_unknown_archive_kind =
Don't know how to build archive of type: {$kind}
codegen_llvm_target_feature_disable_or_enable =
target features {$features} must all be enabled or disabled together
codegen_llvm_missing_features =
add the missing features in a `target_feature` attribute