Attributes on function calls

For a custom clang-tidy check, I need to be able to add an attribute to a function call (not function declaration). I have never added an attribute before. Does clang support attributes on function calls? I see that CallExpr derives from DStmt<Expr> in StmtNodes.td and the documentation on adding attributes states that SubjectList of an attribute can be a statement node. Before I attempt this, can anyone tell me if this is even going to work? Will this involve making changes in parser (which I would really like to avoid)? Ideally, I want to be able to add the attribute in Attr.td and then be able to query it in the check. Is there an existing attribute that I can model this after?

/Riyaz

For a custom clang-tidy check, I need to be able to add an attribute to a function call (not function declaration). I have never added an attribute before. Does clang support attributes on function calls?

Sort of. Clang parses C++11-style attributes on expression statements,
but we do not currently have any attributes that appertain to an
expression statement.

I see that CallExpr derives from DStmt<Expr> in StmtNodes.td and the documentation on adding attributes states that SubjectList of an attribute can be a statement node. Before I attempt this, can anyone tell me if this is even going to work?

It will with C++11-style attributes, but it won't with GNU-style attributes.

Will this involve making changes in parser (which I would really like to avoid)? Ideally, I want to be able to add the attribute in Attr.td and then be able to query it in the check. Is there an existing attribute that I can model this after?

You shouldn't have to change the parser for this. Instead, you would
add the attribute to Attr.td as a StmtAttr, and then add the logic to
convert the parsed attribute into a semantic attribute in
SemaStmtAttr.cpp. There are some other statement attributes that you
can sort of model this after, but none of them appertain to
expressions.

~Aaron

Thanks. I will try C++ attributes. The bummer is that I need some solution for C code too. I will try -x c++ (for the checker only) and see what it throws up. Also our code is not ported to C++11 yet but I will see if I can enable it only for the checker.

-Riyaz