[cfe-dev] Read/Write Accesses of global variables in a Function body...

Eli Friedman eli.friedman at gmail.com
Mon Dec 19 12:06:58 PST 2011


On Mon, Dec 19, 2011 at 11:58 AM, Peter <clang_llvm_123-4 at yahoo.de> wrote:
> Thanks a lot Eli,... for your reply...
>
>>having the AST visitor look for assignment operators rather than doing that
>> part yourself.
> I did everything myself because I wanted to start from a given function...
> How do I make sure that my visitor only visits the body of a given function?
> Do I
> have to implement two different visitors, one that only implements
> 'VisitFunctionDecl' to
> find the function in question and then once found, call the other visitor
> with the function body
> to only visit the 'DeclRefExpr' expressions?

>From the docs for RecursiveASTVisitor, it looks like you can override
TraverseFunctionDecl to suppress recursion if necessary.

>>hasLinkage(), or maybe hasGlobalStorage()?
> ...hasLinkage is what I was looking for... ;)
>
>>If you're just looking for simple assignments,
> I guess for the write access I do, but for the read access I need any
> occurrence within
> the function body. Does that mean I have to implement a visitor method for
> any possible rvalue
> expression, or is it maybe enough to only visit the 'DeclRefExpr' ?

Any use of the variable will have an associated DeclRefExpr, so you
won't miss any references to the variable.

-Eli



More information about the cfe-dev mailing list