Apply custom statement attribute on AST

Hello,

As currently clang doesn’t allow custom attribute to be applied on AST without modification of its source code I am using built in attribute kind with custom arguments parser to do it.
It works with attributes applying to declaration due to class Decl has the method to add attribute.
However class ‘Stmt’ doesn’t have such interface.
Instead to add attribute to statement a ‘AttributedStmt’ should be created that wrap original attribute.
In such case it’s impossible to apply attribute to statement using ParsedAttrInfo interface because it requires pointer to original Stmt pointer to substitute it with AttributedStmt that is not exposed via it.

Is the any trick/hack to resolve it without modifying clang source code?

Unfortunately, attribute plugins do not yet support statement or type attributes, only declaration attributes. So you would have to modify Clang’s source to be able to support adding statement attributes.

Thanks for reply.
Is there a plan or PR to complete the attribute plugin component?

Plugin-based attributes are still a work in progress, but the person initially working on them was focused solely on declaration attributes. As far as I’m aware, nobody is actively working on this functionality for statement (or type) attributes, so we welcome any patches improving this functionality.

1 Like

I see.
My team is very interesting in plugin-based attributes and we will try to contribute in the feature to make it more mature.

1 Like

If you do come up with some patches, feel free to add me and @erichkeane as reviewers; we’d be happy to help!

1 Like