This is an archive of the discontinued LLVM Phabricator instance.

[Clang] Fix: Restore warning inadvertently removed by D126061.
ClosedPublic

Authored by mboehme on Jun 24 2022, 12:18 AM.

Details

Summary

Before D126061, Clang would warn about this code

struct X {
    [[deprecated]] struct Y {};
};

with the warning

attribute 'deprecated' is ignored, place it after "struct" to apply attribute to type declaration

D126061 inadvertently caused this warning to no longer be emitted. This patch
restores the previous behavior.

The reason for the bug is that after D126061, C++11 attributes applied to a
member declaration are no longer placed in DS.getAttributes() but are instead
tracked in a separate list (DeclAttrs). In the case of a free-standing
decl-specifier-seq, we would simply ignore the contents of this list. Instead,
we now pass the list on to Sema::ParsedFreeStandingDeclSpec() so that it can
issue the appropriate warning.

Diff Detail

Event Timeline

mboehme created this revision.Jun 24 2022, 12:18 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 24 2022, 12:18 AM
mboehme requested review of this revision.Jun 24 2022, 12:18 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 24 2022, 12:18 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript

Thank you for the quick fix! I had a question about why only one of the two interfaces needed to be updated and whether we thought that was sensible, but otherwise the changes here look correct to me.

clang/lib/Sema/SemaDecl.cpp
4631–4637

It's surprising that we don't need to update this interface as well; is that inconsistency desired?

mboehme updated this revision to Diff 439708.Jun 24 2022, 5:20 AM

Changes in response to review comments.

mboehme marked an inline comment as done.Jun 24 2022, 5:21 AM
mboehme added inline comments.
clang/lib/Sema/SemaDecl.cpp
4631–4637

This is OK because every caller of this overload happens to do ProhibitAttributes(DeclAttrs).

But now that you bring this up, I realize that this is risky. What if we add another caller in the future that doesn’t do ProhibitAttribubtes(DeclAttrs)? And even in the current situation, I think it makes sense to be explicit that we’re passing an empty list of attributes.

So I’ve added the DeclAttrs parameter to this function too, and now pass ParsedAttributesView::none() at the callsites.

miyuki added a subscriber: miyuki.Jun 24 2022, 7:02 AM
mboehme updated this revision to Diff 440134.Jun 27 2022, 2:01 AM
mboehme marked an inline comment as done.

Turn off clang-format for attr-declspec-ignored.cpp.

It has existing formatting (indentation within namespaces) that's incompatible
with clang-format.

aaron.ballman accepted this revision.Jun 27 2022, 6:29 AM

LGTM aside from a minor nit in the testing.

clang/lib/Sema/SemaDecl.cpp
4631–4637

Thanks, I think this is more clear.

clang/test/SemaCXX/attr-declspec-ignored.cpp
3–6

We don't typically put clang-format markings into tests -- we don't require that tests be formatted, and it's a bug that precommit CI continues to fail because of it (https://github.com/llvm/llvm-project/issues/55982).

Feel free to remove this bit when landing.

62

Same here for this one.

This revision is now accepted and ready to land.Jun 27 2022, 6:29 AM
mboehme updated this revision to Diff 440492.Jun 27 2022, 11:47 PM

Remove clang-format directives from test.

mboehme marked 2 inline comments as done.Jun 27 2022, 11:48 PM
mboehme added inline comments.
clang/test/SemaCXX/attr-declspec-ignored.cpp
3–6

Got it. Done!

I've also commented on the bug.

62

Done.

mboehme updated this revision to Diff 440494.Jun 27 2022, 11:51 PM
mboehme marked 2 inline comments as done.

Remove trailing spaces

This revision was landed with ongoing or failed builds.Jun 27 2022, 11:53 PM
This revision was automatically updated to reflect the committed changes.

Thanks for fixing the issue.