Hi guys,<div>I'm using libtooling to develop a tool to instrument source code. I need to record the left values of assignment statements.</div><div>I tried the `VisitBinaryOperator` function in `RecursiveASTVisitor`. The code looked like this:</div><div><br></div><div>```cpp</div><div><pre style="  ;; font-size: 9pt; "><span style="color:#000080;font-weight:bold;">bool </span>VisitBinaryOperator(<span style="color:#008080;">BinaryOperator </span>*b){<br>    <span style="color:#000080;font-weight:bold;">if</span>(b->isAssignmentOp()){<br>        Stmt <span style="font-size: 9pt;">*lhs = binaryOperator->getLHS();</span></pre><pre style="  ;; font-size: 9pt; ">        if <span style="font-size: 9pt;">(</span><span style="font-size: 9pt; color: rgb(0, 0, 128); font-weight: bold;">const </span><span style="font-size: 9pt; color: rgb(0, 128, 128);">DeclRefExpr </span><span style="font-size: 9pt;">*declRefExpr = dyn_cast<</span><span style="font-size: 9pt; color: rgb(0, 128, 128);">DeclRefExpr</span><span style="font-size: 9pt;">>(lhs))</span><pre style="  ;; font-size: 9pt; ">        {<br>            <span style="color:#808080;font-style:italic;">// It's a reference to a declaration...<br></span><span style="color:#808080;font-style:italic;">            </span><span style="color:#000080;font-weight:bold;">if </span>(<span style="color:#000080;font-weight:bold;">const </span><span style="color:#008080;">VarDecl </span>*VD = dyn_cast<<span style="color:#008080;">VarDecl</span>>(declRefExpr->getDecl()))<br>            {<br>                <span style="color:#808080;font-style:italic;">// It's a reference to a variable (a local, function parameter, global, or static data member).<br></span><span style="color:#808080;font-style:italic;">                </span><span style="color:#371f80;">string </span>s = VD->getType().getAsString();</pre><pre style="  ;; font-size: 9pt; ">                if <span style="font-size: 9pt;">(s </span><span style="font-size: 9pt; color: rgb(0, 128, 128);">== </span><span style="font-size: 9pt; color: rgb(0, 128, 0); font-weight: bold;">"int" </span><span style="font-size: 9pt;">|| s </span><span style="font-size: 9pt; color: rgb(0, 128, 128);">== </span><span style="font-size: 9pt; color: rgb(0, 128, 0); font-weight: bold;">"float" </span><span style="font-size: 9pt;">|| s </span><span style="font-size: 9pt; color: rgb(0, 128, 128);">== </span><span style="font-size: 9pt; color: rgb(0, 128, 0); font-weight: bold;">"double"</span><span style="font-size: 9pt;">)</span></pre><pre style="  ;; font-size: 9pt; "><span style="font-size: 9pt;">                    //do something</span></pre><pre style="  ;; font-size: 9pt; "><span style="font-size: 9pt;">            }</span></pre><pre style="  ;; font-size: 9pt; "><span style="font-size: 9pt;">        }</span></pre><pre style="  ;; font-size: 9pt; "><span style="color:#000080;font-weight:bold;">        if </span>(<span style="color:#000080;font-weight:bold;">const </span><span style="color:#008080;">MemberExpr </span>*memberRefExpr = dyn_cast<<span style="color:#008080;">MemberExpr</span>>(lhs))<br>        {<br>            <span style="color:#808080;font-style:italic;">// It's a reference to a declaration...<br></span><span style="color:#808080;font-style:italic;">            </span><span style="color:#000080;font-weight:bold;">if </span>(<span style="color:#008080;">ValueDecl </span>*VD = memberRefExpr->getMemberDecl())<br>            {<br>                <span style="color:#808080;font-style:italic;">// It's a reference to a variable (a local, function parameter, global, or static data member).<br></span><span style="color:#808080;font-style:italic;">                </span><span style="color:#371f80;">string </span>s = VD->getType().getAsString();<br>                <span style="color:#008080;">llvm</span>::outs()<span style="color:#008080;"><<</span><span style="color:#008000;font-weight:bold;">"type"</span><span style="color:#008080;"><<</span>s<span style="color:#008080;"><<</span><span style="color:#008000;font-weight:bold;">'</span><span style="color:#000080;font-weight:bold;">\n</span><span style="color:#008000;font-weight:bold;">'</span>;<br>                <span style="color:#000080;font-weight:bold;">if </span>(s <span style="color:#008080;">== </span><span style="color:#008000;font-weight:bold;">"int" </span>|| s <span style="color:#008080;">== </span><span style="color:#008000;font-weight:bold;">"float" </span>|| s <span style="color:#008080;">== </span><span style="color:#008000;font-weight:bold;">"double"</span>)<br>                    //do something</pre><pre style="  ;; font-size: 9pt; ">            }</pre><pre style="  ;; font-size: 9pt; ">        }</pre>    }<br>    <span style="color:#000080;font-weight:bold;">return true</span>;<br>}</pre></div><div>```</div><div><br></div><div>Then I tested this code on a .c file, the content includes this:</div><div>```c</div><div><div>void setForceMethod(NbodyModel *theModel,int force_method) {</div><div>    theModel->force_method=force_method;</div><div>}</div><div>void setTreeRangeCoefficient(NbodyModel *theModel,double coefficient) {</div><div>    theModel->treeRangeCoefficient=coefficient;</div><div>}</div><div>void setIntMethod(NbodyModel *theModel,int int_method) {</div><div>    theModel->int_method=int_method;</div><div>}</div></div><div>```</div><div><br></div><div>The result is the code didn't catch the assignment inside these functions meanwhile other </div><div><br></div><div>The run command is `test nbody.c test.h null -DHAS_X11 -D_REENTRANT -D_USE_PTHREADS -DHAS_MPI -DHAS_FFTW3 -DUSE_PPPM` and</div><div>the `-DHAS_X11 -D_REENTRANT -D_USE_PTHREADS -DHAS_MPI -DHAS_FFTW3 -DUSE_PPPM` was passed to <span style="  ;; font-size: 9pt; white-space: pre-wrap; color: rgb(0, 128, 128); ">CompilerInvocation</span><span style="  ;; font-size: 9pt; white-space: pre-wrap; ">::</span><span style="  ;; font-size: 9pt; white-space: pre-wrap; background-color: rgb(228, 228, 255); ">CreateFromArgs</span></div><div><span style="  ;; font-size: 9pt; white-space: pre-wrap; background-color: rgb(228, 228, 255); "><br></span></div><div>Any ideas why I can't visit these things?</div>