Rollup merge of #120631 - saethlin:invalid-target-ice, r=compiler-errors
Emit a diagnostic for invalid target options This turns the ICE in https://github.com/rust-lang/rust/issues/120625 into a translatable diagnostic.
This commit is contained in:
commit
8906977542
@ -28,6 +28,8 @@ codegen_llvm_invalid_minimum_alignment_not_power_of_two =
|
|||||||
codegen_llvm_invalid_minimum_alignment_too_large =
|
codegen_llvm_invalid_minimum_alignment_too_large =
|
||||||
invalid minimum global alignment: {$align} is too large
|
invalid minimum global alignment: {$align} is too large
|
||||||
|
|
||||||
|
codegen_llvm_invalid_target_feature_prefix = target feature `{$feature}` must begin with a `+` or `-`"
|
||||||
|
|
||||||
codegen_llvm_load_bitcode = failed to load bitcode of module "{$name}"
|
codegen_llvm_load_bitcode = failed to load bitcode of module "{$name}"
|
||||||
codegen_llvm_load_bitcode_with_llvm_err = failed to load bitcode of module "{$name}": {$llvm_err}
|
codegen_llvm_load_bitcode_with_llvm_err = failed to load bitcode of module "{$name}": {$llvm_err}
|
||||||
|
|
||||||
|
@ -253,3 +253,9 @@ pub struct MismatchedDataLayout<'a> {
|
|||||||
pub llvm_target: &'a str,
|
pub llvm_target: &'a str,
|
||||||
pub llvm_layout: &'a str,
|
pub llvm_layout: &'a str,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Diagnostic)]
|
||||||
|
#[diag(codegen_llvm_invalid_target_feature_prefix)]
|
||||||
|
pub(crate) struct InvalidTargetFeaturePrefix<'a> {
|
||||||
|
pub feature: &'a str,
|
||||||
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use crate::back::write::create_informational_target_machine;
|
use crate::back::write::create_informational_target_machine;
|
||||||
use crate::errors::{
|
use crate::errors::{
|
||||||
PossibleFeature, TargetFeatureDisableOrEnable, UnknownCTargetFeature,
|
InvalidTargetFeaturePrefix, PossibleFeature, TargetFeatureDisableOrEnable,
|
||||||
UnknownCTargetFeaturePrefix, UnstableCTargetFeature,
|
UnknownCTargetFeature, UnknownCTargetFeaturePrefix, UnstableCTargetFeature,
|
||||||
};
|
};
|
||||||
use crate::llvm;
|
use crate::llvm;
|
||||||
use libc::c_int;
|
use libc::c_int;
|
||||||
@ -511,7 +511,7 @@ pub(crate) fn global_llvm_features(sess: &Session, diagnostics: bool) -> Vec<Str
|
|||||||
sess.target
|
sess.target
|
||||||
.features
|
.features
|
||||||
.split(',')
|
.split(',')
|
||||||
.filter(|v| !v.is_empty() && backend_feature_name(v).is_some())
|
.filter(|v| !v.is_empty() && backend_feature_name(sess, v).is_some())
|
||||||
.map(String::from),
|
.map(String::from),
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -535,7 +535,7 @@ pub(crate) fn global_llvm_features(sess: &Session, diagnostics: bool) -> Vec<Str
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let feature = backend_feature_name(s)?;
|
let feature = backend_feature_name(sess, s)?;
|
||||||
// Warn against use of LLVM specific feature names and unstable features on the CLI.
|
// Warn against use of LLVM specific feature names and unstable features on the CLI.
|
||||||
if diagnostics {
|
if diagnostics {
|
||||||
let feature_state = supported_features.iter().find(|&&(v, _)| v == feature);
|
let feature_state = supported_features.iter().find(|&&(v, _)| v == feature);
|
||||||
@ -611,11 +611,11 @@ pub(crate) fn global_llvm_features(sess: &Session, diagnostics: bool) -> Vec<Str
|
|||||||
/// Returns a feature name for the given `+feature` or `-feature` string.
|
/// Returns a feature name for the given `+feature` or `-feature` string.
|
||||||
///
|
///
|
||||||
/// Only allows features that are backend specific (i.e. not [`RUSTC_SPECIFIC_FEATURES`].)
|
/// Only allows features that are backend specific (i.e. not [`RUSTC_SPECIFIC_FEATURES`].)
|
||||||
fn backend_feature_name(s: &str) -> Option<&str> {
|
fn backend_feature_name<'a>(sess: &Session, s: &'a str) -> Option<&'a str> {
|
||||||
// features must start with a `+` or `-`.
|
// features must start with a `+` or `-`.
|
||||||
let feature = s.strip_prefix(&['+', '-'][..]).unwrap_or_else(|| {
|
let feature = s
|
||||||
bug!("target feature `{}` must begin with a `+` or `-`", s);
|
.strip_prefix(&['+', '-'][..])
|
||||||
});
|
.unwrap_or_else(|| sess.dcx().emit_fatal(InvalidTargetFeaturePrefix { feature: s }));
|
||||||
// Rustc-specific feature requests like `+crt-static` or `-crt-static`
|
// Rustc-specific feature requests like `+crt-static` or `-crt-static`
|
||||||
// are not passed down to LLVM.
|
// are not passed down to LLVM.
|
||||||
if RUSTC_SPECIFIC_FEATURES.contains(&feature) {
|
if RUSTC_SPECIFIC_FEATURES.contains(&feature) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user