[cfe-dev] Attributes on function calls

Riyaz Puthiyapurayil via cfe-dev cfe-dev at lists.llvm.org
Wed Sep 21 11:10:24 PDT 2016

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.


> -----Original Message-----
> From: aaron.ballman at gmail.com [mailto:aaron.ballman at gmail.com] On
> Behalf Of Aaron Ballman
> Sent: Wednesday, September 21, 2016 6:00 AM
> To: Riyaz Puthiyapurayil <Riyaz.Puthiyapurayil at synopsys.com>
> Cc: cfe-dev at lists.llvm.org
> Subject: Re: [cfe-dev] Attributes on function calls
> On Tue, Sep 20, 2016 at 9:21 PM, Riyaz Puthiyapurayil via cfe-dev <cfe-
> dev at lists.llvm.org> wrote:
> > 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
> >
> > /Riyaz
> > _______________________________________________
> > cfe-dev mailing list
> > cfe-dev at lists.llvm.org
> > http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

More information about the cfe-dev mailing list