Quantcast

[RFC] Pragma that applies a specified attribute to declarations

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[RFC] Pragma that applies a specified attribute to declarations

Philip Reames via cfe-dev
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
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [RFC] Pragma that applies a specified attribute to declarations

Philip Reames via cfe-dev
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 <[hidden email]> 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
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev



_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [RFC] Pragma that applies a specified attribute to declarations

Philip Reames via cfe-dev


On 02/13/2017 06:46 PM, Reid Kleckner via cfe-dev wrote:
Sounds totally reasonable.

I agree, but can you be more specific about how this will work? Does this apply only to function declarations or to all declarations? If the latter, will the attribute be applied to all relevant things in the subject list for the attribute? Will parsing be delayed? I'm wondering how this might work with enable_if.

Also, I don't think we should restrict this to declarations because applying to definitions would be useful too. For example push(__attribute__((target("avx")))) seems useful.

 -Hal

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 <[hidden email]> 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
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev




_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

-- 
Hal Finkel
Lead, Compiler Technology and Programming Languages
Leadership Computing Facility
Argonne National Laboratory

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [RFC] Pragma that applies a specified attribute to declarations

Philip Reames via cfe-dev


On 13 February 2017 at 20:18, Hal Finkel <[hidden email]> wrote:


On 02/13/2017 06:46 PM, Reid Kleckner via cfe-dev wrote:
Sounds totally reasonable.

I agree, but can you be more specific about how this will work? Does this apply only to function declarations or to all declarations? If the latter, will the attribute be applied to all relevant things in the subject list for the attribute? Will parsing be delayed? I'm wondering how this might work with enable_if.

I think the set of declarations that can receive an attribute should be attribute specific, and should apply to all the relevant things in the subject list. For example, an attribute like 'annotate' should be applied to all of the declarations that are declared in the active range of the #pragma, but an attribute like 'availability' should be applied only to named declarations. 
 
Initially I think that attribute parsing should be done immediately, so attributes that are parsed late won't be supported at the start. 


Also, I don't think we should restrict this to declarations because applying to definitions would be useful too. For example push(__attribute__((target("avx")))) seems useful.

I guess that could be an attribute specific rule as well.
 

 -Hal

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 <[hidden email]> 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
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev




_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

-- 
Hal Finkel
Lead, Compiler Technology and Programming Languages
Leadership Computing Facility
Argonne National Laboratory



_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Loading...