1
Fork 0

Further codegen_attrs cleanups

This commit is contained in:
Nilstrieb 2023-03-13 19:35:24 +00:00
parent e4ab642e8c
commit 1d70bd4970

View file

@ -194,16 +194,16 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: DefId) -> CodegenFnAttrs {
} }
sym::cmse_nonsecure_entry => { sym::cmse_nonsecure_entry => {
if let Some(fn_sig) = fn_sig() if let Some(fn_sig) = fn_sig()
&& !matches!(fn_sig.skip_binder().abi(), abi::Abi::C { .. }) && !matches!(fn_sig.skip_binder().abi(), abi::Abi::C { .. })
{ {
struct_span_err!( struct_span_err!(
tcx.sess, tcx.sess,
attr.span, attr.span,
E0776, E0776,
"`#[cmse_nonsecure_entry]` requires C ABI" "`#[cmse_nonsecure_entry]` requires C ABI"
) )
.emit(); .emit();
} }
if !tcx.sess.target.llvm_target.contains("thumbv8m") { if !tcx.sess.target.llvm_target.contains("thumbv8m") {
struct_span_err!(tcx.sess, attr.span, E0775, "`#[cmse_nonsecure_entry]` is only valid for targets with the TrustZone-M extension") struct_span_err!(tcx.sess, attr.span, E0775, "`#[cmse_nonsecure_entry]` is only valid for targets with the TrustZone-M extension")
.emit(); .emit();
@ -215,12 +215,12 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: DefId) -> CodegenFnAttrs {
} }
sym::track_caller => { sym::track_caller => {
if !tcx.is_closure(did.to_def_id()) if !tcx.is_closure(did.to_def_id())
&& let Some(fn_sig) = fn_sig() && let Some(fn_sig) = fn_sig()
&& fn_sig.skip_binder().abi() != abi::Abi::Rust && fn_sig.skip_binder().abi() != abi::Abi::Rust
{ {
struct_span_err!(tcx.sess, attr.span, E0737, "`#[track_caller]` requires Rust ABI") struct_span_err!(tcx.sess, attr.span, E0737, "`#[track_caller]` requires Rust ABI")
.emit(); .emit();
} }
if tcx.is_closure(did.to_def_id()) && !tcx.features().closure_track_caller { if tcx.is_closure(did.to_def_id()) && !tcx.features().closure_track_caller {
feature_err( feature_err(
&tcx.sess.parse_sess, &tcx.sess.parse_sess,
@ -331,28 +331,38 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: DefId) -> CodegenFnAttrs {
no_sanitize_span = Some(attr.span); no_sanitize_span = Some(attr.span);
if let Some(list) = attr.meta_item_list() { if let Some(list) = attr.meta_item_list() {
for item in list.iter() { for item in list.iter() {
if item.has_name(sym::address) { match item.ident().map(|ident| ident.name) {
codegen_fn_attrs.no_sanitize |= Some(sym::address) => {
SanitizerSet::ADDRESS | SanitizerSet::KERNELADDRESS; codegen_fn_attrs.no_sanitize |=
} else if item.has_name(sym::cfi) { SanitizerSet::ADDRESS | SanitizerSet::KERNELADDRESS;
codegen_fn_attrs.no_sanitize |= SanitizerSet::CFI; }
} else if item.has_name(sym::kcfi) { Some(sym::cfi) => {
codegen_fn_attrs.no_sanitize |= SanitizerSet::KCFI; codegen_fn_attrs.no_sanitize |= SanitizerSet::CFI;
} else if item.has_name(sym::memory) { }
codegen_fn_attrs.no_sanitize |= SanitizerSet::MEMORY; Some(sym::kcfi) => {
} else if item.has_name(sym::memtag) { codegen_fn_attrs.no_sanitize |= SanitizerSet::KCFI;
codegen_fn_attrs.no_sanitize |= SanitizerSet::MEMTAG; }
} else if item.has_name(sym::shadow_call_stack) { Some(sym::memory) => {
codegen_fn_attrs.no_sanitize |= SanitizerSet::SHADOWCALLSTACK; codegen_fn_attrs.no_sanitize |= SanitizerSet::MEMORY;
} else if item.has_name(sym::thread) { }
codegen_fn_attrs.no_sanitize |= SanitizerSet::THREAD; Some(sym::memtag) => {
} else if item.has_name(sym::hwaddress) { codegen_fn_attrs.no_sanitize |= SanitizerSet::MEMTAG;
codegen_fn_attrs.no_sanitize |= SanitizerSet::HWADDRESS; }
} else { Some(sym::shadow_call_stack) => {
tcx.sess codegen_fn_attrs.no_sanitize |= SanitizerSet::SHADOWCALLSTACK;
}
Some(sym::thread) => {
codegen_fn_attrs.no_sanitize |= SanitizerSet::THREAD;
}
Some(sym::hwaddress) => {
codegen_fn_attrs.no_sanitize |= SanitizerSet::HWADDRESS;
}
_ => {
tcx.sess
.struct_span_err(item.span(), "invalid argument for `no_sanitize`") .struct_span_err(item.span(), "invalid argument for `no_sanitize`")
.note("expected one of: `address`, `cfi`, `hwaddress`, `kcfi`, `memory`, `memtag`, `shadow-call-stack`, or `thread`") .note("expected one of: `address`, `cfi`, `hwaddress`, `kcfi`, `memory`, `memtag`, `shadow-call-stack`, or `thread`")
.emit(); .emit();
}
} }
} }
} }
@ -417,34 +427,23 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: DefId) -> CodegenFnAttrs {
}) })
} }
sym::repr => { sym::repr => {
codegen_fn_attrs.alignment = match attr.meta_item_list() { codegen_fn_attrs.alignment = if let Some(items) = attr.meta_item_list()
Some(items) => match items.as_slice() { && let [item] = items.as_slice()
[item] => match item.name_value_literal() { && let Some((sym::align, literal)) = item.name_value_literal()
Some((sym::align, literal)) => { {
let alignment = rustc_attr::parse_alignment(&literal.kind); rustc_attr::parse_alignment(&literal.kind).map_err(|msg| {
struct_span_err!(
match alignment { tcx.sess.diagnostic(),
Ok(align) => Some(align), attr.span,
Err(msg) => { E0589,
struct_span_err!( "invalid `repr(align)` attribute: {}",
tcx.sess.diagnostic(), msg
attr.span, )
E0589, .emit();
"invalid `repr(align)` attribute: {}", })
msg .ok()
) } else {
.emit(); None
None
}
}
}
_ => None,
},
[] => None,
_ => None,
},
None => None,
}; };
} }
_ => {} _ => {}