rustc_codegen_ssa: cleanup codegen attrs
This commit is contained in:
parent
a821785641
commit
73d5fe153b
1 changed files with 56 additions and 62 deletions
|
@ -1,7 +1,6 @@
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
use rustc_abi::ExternAbi;
|
use rustc_abi::ExternAbi;
|
||||||
use rustc_ast::attr::list_contains_name;
|
|
||||||
use rustc_ast::expand::autodiff_attrs::{
|
use rustc_ast::expand::autodiff_attrs::{
|
||||||
AutoDiffAttrs, DiffActivity, DiffMode, valid_input_activity, valid_ret_activity,
|
AutoDiffAttrs, DiffActivity, DiffMode, valid_input_activity, valid_ret_activity,
|
||||||
};
|
};
|
||||||
|
@ -385,8 +384,9 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
|
||||||
let segments =
|
let segments =
|
||||||
set.path.segments.iter().map(|x| x.ident.name).collect::<Vec<_>>();
|
set.path.segments.iter().map(|x| x.ident.name).collect::<Vec<_>>();
|
||||||
match segments.as_slice() {
|
match segments.as_slice() {
|
||||||
[sym::arm, sym::a32] | [sym::arm, sym::t32] => {
|
[sym::arm, sym::a32 | sym::t32]
|
||||||
if !tcx.sess.target.has_thumb_interworking {
|
if !tcx.sess.target.has_thumb_interworking =>
|
||||||
|
{
|
||||||
struct_span_code_err!(
|
struct_span_code_err!(
|
||||||
tcx.dcx(),
|
tcx.dcx(),
|
||||||
attr.span,
|
attr.span,
|
||||||
|
@ -395,14 +395,9 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
|
||||||
)
|
)
|
||||||
.emit();
|
.emit();
|
||||||
None
|
None
|
||||||
} else if segments[1] == sym::a32 {
|
|
||||||
Some(InstructionSetAttr::ArmA32)
|
|
||||||
} else if segments[1] == sym::t32 {
|
|
||||||
Some(InstructionSetAttr::ArmT32)
|
|
||||||
} else {
|
|
||||||
unreachable!()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
[sym::arm, sym::a32] => Some(InstructionSetAttr::ArmA32),
|
||||||
|
[sym::arm, sym::t32] => Some(InstructionSetAttr::ArmT32),
|
||||||
_ => {
|
_ => {
|
||||||
struct_span_code_err!(
|
struct_span_code_err!(
|
||||||
tcx.dcx(),
|
tcx.dcx(),
|
||||||
|
@ -443,7 +438,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
|
||||||
&& let Some((sym::align, literal)) = item.singleton_lit_list()
|
&& let Some((sym::align, literal)) = item.singleton_lit_list()
|
||||||
{
|
{
|
||||||
rustc_attr_parsing::parse_alignment(&literal.kind)
|
rustc_attr_parsing::parse_alignment(&literal.kind)
|
||||||
.map_err(|msg| {
|
.inspect_err(|msg| {
|
||||||
struct_span_code_err!(
|
struct_span_code_err!(
|
||||||
tcx.dcx(),
|
tcx.dcx(),
|
||||||
literal.span,
|
literal.span,
|
||||||
|
@ -544,26 +539,28 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
|
||||||
}
|
}
|
||||||
|
|
||||||
if attr.is_word() {
|
if attr.is_word() {
|
||||||
InlineAttr::Hint
|
return InlineAttr::Hint;
|
||||||
} else if let Some(ref items) = attr.meta_item_list() {
|
}
|
||||||
|
let Some(ref items) = attr.meta_item_list() else {
|
||||||
|
return ia;
|
||||||
|
};
|
||||||
|
|
||||||
inline_span = Some(attr.span);
|
inline_span = Some(attr.span);
|
||||||
if items.len() != 1 {
|
let [item] = &items[..] else {
|
||||||
struct_span_code_err!(tcx.dcx(), attr.span, E0534, "expected one argument").emit();
|
struct_span_code_err!(tcx.dcx(), attr.span, E0534, "expected one argument").emit();
|
||||||
InlineAttr::None
|
return InlineAttr::None;
|
||||||
} else if list_contains_name(items, sym::always) {
|
};
|
||||||
|
if item.has_name(sym::always) {
|
||||||
InlineAttr::Always
|
InlineAttr::Always
|
||||||
} else if list_contains_name(items, sym::never) {
|
} else if item.has_name(sym::never) {
|
||||||
InlineAttr::Never
|
InlineAttr::Never
|
||||||
} else {
|
} else {
|
||||||
struct_span_code_err!(tcx.dcx(), items[0].span(), E0535, "invalid argument")
|
struct_span_code_err!(tcx.dcx(), item.span(), E0535, "invalid argument")
|
||||||
.with_help("valid inline arguments are `always` and `never`")
|
.with_help("valid inline arguments are `always` and `never`")
|
||||||
.emit();
|
.emit();
|
||||||
|
|
||||||
InlineAttr::None
|
InlineAttr::None
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
ia
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
codegen_fn_attrs.inline = attrs.iter().fold(codegen_fn_attrs.inline, |ia, attr| {
|
codegen_fn_attrs.inline = attrs.iter().fold(codegen_fn_attrs.inline, |ia, attr| {
|
||||||
if !attr.has_name(sym::rustc_force_inline) || !tcx.features().rustc_attrs() {
|
if !attr.has_name(sym::rustc_force_inline) || !tcx.features().rustc_attrs() {
|
||||||
|
@ -594,23 +591,25 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
|
||||||
let err = |sp, s| struct_span_code_err!(tcx.dcx(), sp, E0722, "{}", s).emit();
|
let err = |sp, s| struct_span_code_err!(tcx.dcx(), sp, E0722, "{}", s).emit();
|
||||||
if attr.is_word() {
|
if attr.is_word() {
|
||||||
err(attr.span, "expected one argument");
|
err(attr.span, "expected one argument");
|
||||||
ia
|
return ia;
|
||||||
} else if let Some(ref items) = attr.meta_item_list() {
|
}
|
||||||
|
let Some(ref items) = attr.meta_item_list() else {
|
||||||
|
return OptimizeAttr::Default;
|
||||||
|
};
|
||||||
|
|
||||||
inline_span = Some(attr.span);
|
inline_span = Some(attr.span);
|
||||||
if items.len() != 1 {
|
let [item] = &items[..] else {
|
||||||
err(attr.span, "expected one argument");
|
err(attr.span, "expected one argument");
|
||||||
OptimizeAttr::Default
|
return OptimizeAttr::Default;
|
||||||
} else if list_contains_name(items, sym::size) {
|
};
|
||||||
|
if item.has_name(sym::size) {
|
||||||
OptimizeAttr::Size
|
OptimizeAttr::Size
|
||||||
} else if list_contains_name(items, sym::speed) {
|
} else if item.has_name(sym::speed) {
|
||||||
OptimizeAttr::Speed
|
OptimizeAttr::Speed
|
||||||
} else if list_contains_name(items, sym::none) {
|
} else if item.has_name(sym::none) {
|
||||||
OptimizeAttr::DoNotOptimize
|
OptimizeAttr::DoNotOptimize
|
||||||
} else {
|
} else {
|
||||||
err(items[0].span(), "invalid argument");
|
err(item.span(), "invalid argument");
|
||||||
OptimizeAttr::Default
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
OptimizeAttr::Default
|
OptimizeAttr::Default
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -762,18 +761,13 @@ fn should_inherit_track_caller(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
|
||||||
|
|
||||||
fn check_link_ordinal(tcx: TyCtxt<'_>, attr: &hir::Attribute) -> Option<u16> {
|
fn check_link_ordinal(tcx: TyCtxt<'_>, attr: &hir::Attribute) -> Option<u16> {
|
||||||
use rustc_ast::{LitIntType, LitKind, MetaItemLit};
|
use rustc_ast::{LitIntType, LitKind, MetaItemLit};
|
||||||
let meta_item_list = attr.meta_item_list();
|
let meta_item_list = attr.meta_item_list()?;
|
||||||
let meta_item_list = meta_item_list.as_deref();
|
let [sole_meta_list] = &meta_item_list[..] else {
|
||||||
let sole_meta_list = match meta_item_list {
|
|
||||||
Some([item]) => item.lit(),
|
|
||||||
Some(_) => {
|
|
||||||
tcx.dcx().emit_err(errors::InvalidLinkOrdinalNargs { span: attr.span });
|
tcx.dcx().emit_err(errors::InvalidLinkOrdinalNargs { span: attr.span });
|
||||||
return None;
|
return None;
|
||||||
}
|
|
||||||
_ => None,
|
|
||||||
};
|
};
|
||||||
if let Some(MetaItemLit { kind: LitKind::Int(ordinal, LitIntType::Unsuffixed), .. }) =
|
if let Some(MetaItemLit { kind: LitKind::Int(ordinal, LitIntType::Unsuffixed), .. }) =
|
||||||
sole_meta_list
|
sole_meta_list.lit()
|
||||||
{
|
{
|
||||||
// According to the table at
|
// According to the table at
|
||||||
// https://docs.microsoft.com/en-us/windows/win32/debug/pe-format#import-header, the
|
// https://docs.microsoft.com/en-us/windows/win32/debug/pe-format#import-header, the
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue