Skip to content

Commit 1d70bd4

Browse files
committed
Further codegen_attrs cleanups
1 parent e4ab642 commit 1d70bd4

File tree

1 file changed

+62
-63
lines changed

1 file changed

+62
-63
lines changed

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

+62-63
Original file line numberDiff line numberDiff line change
@@ -194,16 +194,16 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: DefId) -> CodegenFnAttrs {
194194
}
195195
sym::cmse_nonsecure_entry => {
196196
if let Some(fn_sig) = fn_sig()
197-
&& !matches!(fn_sig.skip_binder().abi(), abi::Abi::C { .. })
198-
{
199-
struct_span_err!(
200-
tcx.sess,
201-
attr.span,
202-
E0776,
203-
"`#[cmse_nonsecure_entry]` requires C ABI"
204-
)
205-
.emit();
206-
}
197+
&& !matches!(fn_sig.skip_binder().abi(), abi::Abi::C { .. })
198+
{
199+
struct_span_err!(
200+
tcx.sess,
201+
attr.span,
202+
E0776,
203+
"`#[cmse_nonsecure_entry]` requires C ABI"
204+
)
205+
.emit();
206+
}
207207
if !tcx.sess.target.llvm_target.contains("thumbv8m") {
208208
struct_span_err!(tcx.sess, attr.span, E0775, "`#[cmse_nonsecure_entry]` is only valid for targets with the TrustZone-M extension")
209209
.emit();
@@ -215,12 +215,12 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: DefId) -> CodegenFnAttrs {
215215
}
216216
sym::track_caller => {
217217
if !tcx.is_closure(did.to_def_id())
218-
&& let Some(fn_sig) = fn_sig()
219-
&& fn_sig.skip_binder().abi() != abi::Abi::Rust
220-
{
221-
struct_span_err!(tcx.sess, attr.span, E0737, "`#[track_caller]` requires Rust ABI")
222-
.emit();
223-
}
218+
&& let Some(fn_sig) = fn_sig()
219+
&& fn_sig.skip_binder().abi() != abi::Abi::Rust
220+
{
221+
struct_span_err!(tcx.sess, attr.span, E0737, "`#[track_caller]` requires Rust ABI")
222+
.emit();
223+
}
224224
if tcx.is_closure(did.to_def_id()) && !tcx.features().closure_track_caller {
225225
feature_err(
226226
&tcx.sess.parse_sess,
@@ -331,28 +331,38 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: DefId) -> CodegenFnAttrs {
331331
no_sanitize_span = Some(attr.span);
332332
if let Some(list) = attr.meta_item_list() {
333333
for item in list.iter() {
334-
if item.has_name(sym::address) {
335-
codegen_fn_attrs.no_sanitize |=
336-
SanitizerSet::ADDRESS | SanitizerSet::KERNELADDRESS;
337-
} else if item.has_name(sym::cfi) {
338-
codegen_fn_attrs.no_sanitize |= SanitizerSet::CFI;
339-
} else if item.has_name(sym::kcfi) {
340-
codegen_fn_attrs.no_sanitize |= SanitizerSet::KCFI;
341-
} else if item.has_name(sym::memory) {
342-
codegen_fn_attrs.no_sanitize |= SanitizerSet::MEMORY;
343-
} else if item.has_name(sym::memtag) {
344-
codegen_fn_attrs.no_sanitize |= SanitizerSet::MEMTAG;
345-
} else if item.has_name(sym::shadow_call_stack) {
346-
codegen_fn_attrs.no_sanitize |= SanitizerSet::SHADOWCALLSTACK;
347-
} else if item.has_name(sym::thread) {
348-
codegen_fn_attrs.no_sanitize |= SanitizerSet::THREAD;
349-
} else if item.has_name(sym::hwaddress) {
350-
codegen_fn_attrs.no_sanitize |= SanitizerSet::HWADDRESS;
351-
} else {
352-
tcx.sess
334+
match item.ident().map(|ident| ident.name) {
335+
Some(sym::address) => {
336+
codegen_fn_attrs.no_sanitize |=
337+
SanitizerSet::ADDRESS | SanitizerSet::KERNELADDRESS;
338+
}
339+
Some(sym::cfi) => {
340+
codegen_fn_attrs.no_sanitize |= SanitizerSet::CFI;
341+
}
342+
Some(sym::kcfi) => {
343+
codegen_fn_attrs.no_sanitize |= SanitizerSet::KCFI;
344+
}
345+
Some(sym::memory) => {
346+
codegen_fn_attrs.no_sanitize |= SanitizerSet::MEMORY;
347+
}
348+
Some(sym::memtag) => {
349+
codegen_fn_attrs.no_sanitize |= SanitizerSet::MEMTAG;
350+
}
351+
Some(sym::shadow_call_stack) => {
352+
codegen_fn_attrs.no_sanitize |= SanitizerSet::SHADOWCALLSTACK;
353+
}
354+
Some(sym::thread) => {
355+
codegen_fn_attrs.no_sanitize |= SanitizerSet::THREAD;
356+
}
357+
Some(sym::hwaddress) => {
358+
codegen_fn_attrs.no_sanitize |= SanitizerSet::HWADDRESS;
359+
}
360+
_ => {
361+
tcx.sess
353362
.struct_span_err(item.span(), "invalid argument for `no_sanitize`")
354363
.note("expected one of: `address`, `cfi`, `hwaddress`, `kcfi`, `memory`, `memtag`, `shadow-call-stack`, or `thread`")
355364
.emit();
365+
}
356366
}
357367
}
358368
}
@@ -417,34 +427,23 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: DefId) -> CodegenFnAttrs {
417427
})
418428
}
419429
sym::repr => {
420-
codegen_fn_attrs.alignment = match attr.meta_item_list() {
421-
Some(items) => match items.as_slice() {
422-
[item] => match item.name_value_literal() {
423-
Some((sym::align, literal)) => {
424-
let alignment = rustc_attr::parse_alignment(&literal.kind);
425-
426-
match alignment {
427-
Ok(align) => Some(align),
428-
Err(msg) => {
429-
struct_span_err!(
430-
tcx.sess.diagnostic(),
431-
attr.span,
432-
E0589,
433-
"invalid `repr(align)` attribute: {}",
434-
msg
435-
)
436-
.emit();
437-
438-
None
439-
}
440-
}
441-
}
442-
_ => None,
443-
},
444-
[] => None,
445-
_ => None,
446-
},
447-
None => None,
430+
codegen_fn_attrs.alignment = if let Some(items) = attr.meta_item_list()
431+
&& let [item] = items.as_slice()
432+
&& let Some((sym::align, literal)) = item.name_value_literal()
433+
{
434+
rustc_attr::parse_alignment(&literal.kind).map_err(|msg| {
435+
struct_span_err!(
436+
tcx.sess.diagnostic(),
437+
attr.span,
438+
E0589,
439+
"invalid `repr(align)` attribute: {}",
440+
msg
441+
)
442+
.emit();
443+
})
444+
.ok()
445+
} else {
446+
None
448447
};
449448
}
450449
_ => {}

0 commit comments

Comments
 (0)