[cfe-dev] [RFC] Pragma that applies a specified attribute to declarations

Reid Kleckner via cfe-dev cfe-dev at lists.llvm.org
Mon Feb 13 16:46:51 PST 2017


Sounds totally reasonable. I prefer '#pragma clang attribute push(...)' to
the other one, since it will fit more easily into our pragma handler code.

The infrastructure for managing pragma stacks that apply attributes to
decls should be in decent shape at this point after adding all the
stack-based MS pragmas. If it isn't, we should refactor things more, since
this is a pretty common pattern.

On Mon, Feb 13, 2017 at 4:24 PM, Alex L via cfe-dev <cfe-dev at lists.llvm.org>
wrote:

> Hi,
>
> I would like to propose a new Clang pragma that would apply a specified
> attribute to some specific declarations in a source file. Initially the
> pragma would only work with annotation-like attributes that explicitly
> opt-in into allowing this pragma. This will ensure that this pragma can
> avoid conflicts with other pragmas that apply attributes like "#pragma
> clang optimize off", etc. The set of declarations that receive the
> attribute would be attribute-specific.
>
> I would like to propose the following syntax:
>
>     #pragma clang attribute push(annotate("important")) // or maybe
> push(__attribute__(annotate("important")))?
>
>     void foo(); // This function will now have the annotate("important")
> attribute.
>
>     #pragma clang attribute pop
>
> We would like to use this pragma to apply the new
> 'external_source_attribute' (https://reviews.llvm.org/D29819) to all of
> the declarations in an Objective-C header file that was auto-generated by
> the Swift compiler without adding additional attribute/macro to each
> declaration.
>
> Do you have any thoughts / suggestions about this proposal?
>
> Cheers,
> Alex
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170213/082df748/attachment.html>


More information about the cfe-dev mailing list