[cfe-dev] Finding all instances of calls to a specific function using ASTMatcher

Saheel Godhane srgodhane at ucdavis.edu
Sat Apr 18 20:09:27 PDT 2015


On Friday, April 17, 2015, Nikola Smiljanic <popizdeh at gmail.com> wrote:

> Use clang-query to try things out, you'll need to generate compilation
> database to use it but that shouldn't be too hard. It sure beats having to
> recompile your code to test it.
>
> The matcher you're after is probably
> callExpr(callee(functionDecl(hasName("malloc"))))
>

Hi Nikola,

I had a related question. Can I run such a matcher on a whole program? I am
currently using the CSA framework but running into some issues and I think
using the matchers suit my task better.

Thanks for your reply!
Saheel.


>
>
> On Tue, Apr 7, 2015 at 10:49 AM, Riyad Parvez <riyad.parvez at gmail.com
> <javascript:_e(%7B%7D,'cvml','riyad.parvez at gmail.com');>> wrote:
> >
> > Hi All,
> >
> > I want to find all the instances of calls to a specific function. Right
> now, I can find all the function calls using ASTMatcher using following
> code:
> >
> > Finder.addMatcher(
> >
> callExpr(hasParent(binaryOperator(hasOperatorName("=")).bind("assignment"))).bind("functionCall"),
> >       &HandlerForFunctionCall);
> >
> > But I want to find all the function calls whose name is say "malloc". I
> know how do that using classic "RecursiveASTVisitor" class, but how can I
> do this using ASTMatcher?
> >
> > Thanks
> > Riyad
> > _______________________________________________
> > cfe-dev mailing list
> > cfe-dev at cs.uiuc.edu
> <javascript:_e(%7B%7D,'cvml','cfe-dev at cs.uiuc.edu');>
> > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20150418/28b67b4b/attachment.html>


More information about the cfe-dev mailing list