1
Fork 0

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

View file

@ -2,7 +2,8 @@ use std::borrow::Cow;
use rustc_errors::fluent; use rustc_errors::fluent;
use rustc_errors::DiagnosticBuilder; use rustc_errors::DiagnosticBuilder;
use rustc_macros::SessionDiagnostic; use rustc_errors::ErrorGuaranteed;
use rustc_macros::{SessionDiagnostic, SessionSubdiagnostic};
use rustc_session::SessionDiagnostic; use rustc_session::SessionDiagnostic;
use rustc_span::Span; use rustc_span::Span;
@ -117,3 +118,29 @@ pub(crate) struct DlltoolFailImportLibrary<'a> {
pub(crate) struct UnknownArchiveKind<'a> { pub(crate) struct UnknownArchiveKind<'a> {
pub kind: &'a str, 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::back::write::create_informational_target_machine;
use crate::errors::UnknownCTargetFeature; use crate::errors::{TargetFeatureDisableOrEnable, UnknownCTargetFeature};
use crate::llvm; use crate::llvm;
use libc::c_int; use libc::c_int;
use rustc_codegen_ssa::target_features::{ 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); features.extend(feats);
if diagnostics && let Some(f) = check_tied_features(sess, &featsmap) { if diagnostics && let Some(f) = check_tied_features(sess, &featsmap) {
sess.err(&format!( sess.emit_err(TargetFeatureDisableOrEnable {
"target features {} must all be enabled or disabled together", features: f,
f.join(", ") span: None
)); });
} }
features features

View file

@ -51,3 +51,9 @@ codegen_llvm_dlltool_fail_import_library =
codegen_llvm_unknown_archive_kind = codegen_llvm_unknown_archive_kind =
Don't know how to build archive of type: {$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