This is an archive of the discontinued LLVM Phabricator instance.

Support for groups of attributes in #pragma clang attribute
ClosedPublic

Authored by erik.pilkington on Oct 23 2018, 4:01 PM.

Details

Summary

This patch allows pushing an empty #pragma clang attribute push, then adding multiple attributes to it, then popping them all with #pragma clang attribute pop, just like #pragma clang diagnostic. We still support the current way of adding these, #pragma clang attribute push(__attribute__((...))), by treating it like a combined push/attribute. This is needed to create macros that behave like:

DO_SOMETHING_BEGIN(attr1, attr2, attr3)
// ...
DO_SOMETHING_END

Which can be called with a variable number of arguments. One possible alternative would be to allow multiple attributes to be specified in the combined push operation, but I chose this method to be more consistent with #pragma clang diagnostic.

Fixes rdar://45496947.

Thanks for taking a look!
Erik

Diff Detail

Repository
rL LLVM

Event Timeline

Thanks! It looks pretty good, just minor nit. could you also update the language extension doc and release notes?

clang/lib/Sema/SemaAttr.cpp
645 ↗(On Diff #170770)

this for loop should have braces.

erik.pilkington marked an inline comment as done.

Add documentation and release notes, {}s. Thanks!

aaron.ballman accepted this revision.Oct 26 2018, 6:23 AM

LGTM aside from some small nits.

clang/docs/LanguageExtensions.rst
2666 ↗(On Diff #171218)

The whitespace changes here are not needed as part of this patch, right? (It's just changing the style of the docs?)

clang/lib/Parse/ParsePragma.cpp
3149 ↗(On Diff #171218)

I'd prefer dropping the auto here.

This revision is now accepted and ready to land.Oct 26 2018, 6:23 AM
arphaman accepted this revision.Oct 26 2018, 2:10 PM

LGTM too when Aaron's comments are addressed

erik.pilkington marked an inline comment as done.Oct 28 2018, 7:30 PM
erik.pilkington added inline comments.
clang/docs/LanguageExtensions.rst
2666 ↗(On Diff #171218)

Oh, no it doesn't make a difference to clang. Just thought that it makes it a bit more obvious that this operation is a combination of:

#pragma clang attribute push
#pragma clang attribute (__attribute__((annotate("custom"))), apply_to = function)
clang/lib/Parse/ParsePragma.cpp
3149 ↗(On Diff #171218)

Sure, done in the commit. Thanks for reviewing!

This revision was automatically updated to reflect the committed changes.