<div dir="ltr">It definitely should match:<div>$ cat /tmp/t.cc</div><div>void f() {</div><div>  int i;</div><div>  i = 2;</div><div>}</div><div><div>$ clang-query /tmp/t.cc --</div><div>Parsing /tmp/t.cc:   0.0015 (100.0%)   0.0015 (100.0%)   0.0018 (100.0%)  </div><div>clang-query> m binaryOperator()</div><div>Match #1:</div><div>/tmp/t.cc:3:3: note: "root" binds here</div><div>  i = 2;</div></div><div><br></div><div>If your code doesn't parse correctly, or doesn't find some headers, all bets are off, so as the post above said, more context needed.</div></div><br><div class="gmail_quote"><div dir="ltr">On Thu, Jan 5, 2017 at 11:55 AM mats petersson via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="gmail_msg"><div class="gmail_msg"><div class="gmail_msg">Then I'm afraid I'm not sure. Maybe the assignments aren't classed as a binary operator any longer?<br class="gmail_msg"><br class="gmail_msg"></div>It would be great if you can produce a COMPLETE (but minimal to show the problem) example of both the code you are working on, and the input that you are giving it, for debugging.<br class="gmail_msg"><br class="gmail_msg">--<br class="gmail_msg"></div>Mats<br class="gmail_msg"></div><div class="gmail_extra gmail_msg"><br class="gmail_msg"><div class="gmail_quote gmail_msg">On 5 January 2017 at 06:51, 詹石岩 via cfe-dev <span dir="ltr" class="gmail_msg"><<a href="mailto:cfe-dev@lists.llvm.org" class="gmail_msg" target="_blank">cfe-dev@lists.llvm.org</a>></span> wrote:<br class="gmail_msg"><blockquote class="gmail_quote gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="gmail_msg">I added code just at the beginning of VisitBinaryOperator like:</div><div class="gmail_msg"><pre style="font-family:"DejaVu Sans Mono"" class="gmail_msg"><font size="2" class="gmail_msg">bool VisitBinaryOperator(BinaryOperator *b){<br class="gmail_msg">    PrintingPolicy policy = PrintingPolicy(this->TheRewriter.getLangOpts());<br class="gmail_msg">    b->printPretty(llvm::errs(), NULL, policy);<br class="gmail_msg">    llvm::errs()<<'\n';<br class="gmail_msg">    if(b->isAssignmentOp()){<br class="gmail_msg">        handler.HandleBinaryOperator(b);<br class="gmail_msg">    }<br class="gmail_msg">    return true;<br class="gmail_msg">}</font></pre><pre style="font-family:"DejaVu Sans Mono"" class="gmail_msg"><font size="2" class="gmail_msg">The test code includes these lines:</font></pre><span class="gmail_msg"><pre style="font-family:"DejaVu Sans Mono"" class="gmail_msg">void setForceMethod(NbodyModel *theModel,int force_method) {<br style="font-family:"lucida Grande",Verdana,"Microsoft YaHei";white-space:normal" class="gmail_msg"><span style="font-family:"lucida Grande",Verdana,"Microsoft YaHei";white-space:normal" class="gmail_msg">    theModel->force_method=force_method;</span><br style="font-family:"lucida Grande",Verdana,"Microsoft YaHei";white-space:normal" class="gmail_msg"><span style="font-family:"lucida Grande",Verdana,"Microsoft YaHei";white-space:normal" class="gmail_msg">}</span><br style="font-family:"lucida Grande",Verdana,"Microsoft YaHei";white-space:normal" class="gmail_msg"><span style="font-family:"lucida Grande",Verdana,"Microsoft YaHei";white-space:normal" class="gmail_msg">void setTreeRangeCoefficient(NbodyModel *theModel,double coefficient) {</span><br style="font-family:"lucida Grande",Verdana,"Microsoft YaHei";white-space:normal" class="gmail_msg"><span style="font-family:"lucida Grande",Verdana,"Microsoft YaHei";white-space:normal" class="gmail_msg">    theModel->treeRangeCoefficient=coefficient;</span><br style="font-family:"lucida Grande",Verdana,"Microsoft YaHei";white-space:normal" class="gmail_msg"><span style="font-family:"lucida Grande",Verdana,"Microsoft YaHei";white-space:normal" class="gmail_msg">}</span><br style="font-family:"lucida Grande",Verdana,"Microsoft YaHei";white-space:normal" class="gmail_msg"><span style="font-family:"lucida Grande",Verdana,"Microsoft YaHei";white-space:normal" class="gmail_msg">void setIntMethod(NbodyModel *theModel,int int_method) {</span><br style="font-family:"lucida Grande",Verdana,"Microsoft YaHei";white-space:normal" class="gmail_msg"><span style="font-family:"lucida Grande",Verdana,"Microsoft YaHei";white-space:normal" class="gmail_msg">    theModel->int_method=int_method;</span><br style="font-family:"lucida Grande",Verdana,"Microsoft YaHei";white-space:normal" class="gmail_msg"><span style="font-family:"lucida Grande",Verdana,"Microsoft YaHei";white-space:normal" class="gmail_msg">}</span></pre></span><pre style="font-family:"DejaVu Sans Mono"" class="gmail_msg">expected output should include these assignments but I didn't find them in terminal.</pre><pre style="font-family:"DejaVu Sans Mono"" class="gmail_msg">I tried `clang -Xclang -ast-dump -fsyntax-only mycode.c` and these assignments were printed out.</pre><pre style="font-family:"DejaVu Sans Mono"" class="gmail_msg">The older version of this tool can get most of these assignments(7 out of 8) but after I added some code, all of them are gone. Does this problem have any relation to compiler? Or the memory layout was messed up by my code?</pre></div><span class="gmail_msg"><blockquote style="margin:0.8em 0px 0.8em 2em;padding:0px 0px 0px 0.7em;border-left:2px solid rgb(221,221,221)" class="gmail_msg"><span style="font-family:"lucida Grande",Verdana,"Microsoft YaHei"" class="gmail_msg">Are you SURE that the VisitBinaryOperator function is not being called? I</span><br style="font-family:"lucida Grande",Verdana,"Microsoft YaHei"" class="gmail_msg"><span style="font-family:"lucida Grande",Verdana,"Microsoft YaHei"" class="gmail_msg">find that highly unlikely (considering that these visitors are quite</span><br style="font-family:"lucida Grande",Verdana,"Microsoft YaHei"" class="gmail_msg"><span style="font-family:"lucida Grande",Verdana,"Microsoft YaHei"" class="gmail_msg">commonly used for all sorts of different purposes, and checking for</span><br style="font-family:"lucida Grande",Verdana,"Microsoft YaHei"" class="gmail_msg"><span style="font-family:"lucida Grande",Verdana,"Microsoft YaHei"" class="gmail_msg">assignments isn't unusual by any means).</span><br style="font-family:"lucida Grande",Verdana,"Microsoft YaHei"" class="gmail_msg"><br style="font-family:"lucida Grande",Verdana,"Microsoft YaHei"" class="gmail_msg"><span style="font-family:"lucida Grande",Verdana,"Microsoft YaHei"" class="gmail_msg">I would expect that the conditions INSIDE your function is what is causing</span><br style="font-family:"lucida Grande",Verdana,"Microsoft YaHei"" class="gmail_msg"><span style="font-family:"lucida Grande",Verdana,"Microsoft YaHei"" class="gmail_msg">problems. Try adding some printout (or set a breakpoint in a debugger) at</span><br style="font-family:"lucida Grande",Verdana,"Microsoft YaHei"" class="gmail_msg"><span style="font-family:"lucida Grande",Verdana,"Microsoft YaHei"" class="gmail_msg">the beginning of the function. I suspect the function is being called, but</span><br style="font-family:"lucida Grande",Verdana,"Microsoft YaHei"" class="gmail_msg"><span style="font-family:"lucida Grande",Verdana,"Microsoft YaHei"" class="gmail_msg">the operands are not the kind you think they are in this case, so your</span><br style="font-family:"lucida Grande",Verdana,"Microsoft YaHei"" class="gmail_msg"><span style="font-family:"lucida Grande",Verdana,"Microsoft YaHei"" class="gmail_msg">printout or "do stuff" isn't happening.</span><br style="font-family:"lucida Grande",Verdana,"Microsoft YaHei"" class="gmail_msg"><br style="font-family:"lucida Grande",Verdana,"Microsoft YaHei"" class="gmail_msg"><span style="font-family:"lucida Grande",Verdana,"Microsoft YaHei"" class="gmail_msg">--</span><br style="font-family:"lucida Grande",Verdana,"Microsoft YaHei"" class="gmail_msg"><span style="font-family:"lucida Grande",Verdana,"Microsoft YaHei"" class="gmail_msg">Mats</span><br style="font-family:"lucida Grande",Verdana,"Microsoft YaHei"" class="gmail_msg"></blockquote><div class="gmail_msg"><br class="gmail_msg"></div></span><div class="gmail_msg"><div style="color:#909090;font-family:Arial Narrow;font-size:12px" class="gmail_msg">------------------</div><div style="font-size:14px;font-family:Verdana;color:#000" class="gmail_msg"><div class="gmail_msg"><font face="幼圆" size="2" class="gmail_msg">----</font></div><font face="幼圆" size="2" class="gmail_msg">祝好!</font><span class="m_1376082856210054035HOEnZb gmail_msg"><font color="#888888" class="gmail_msg"><div class="gmail_msg"><font face="幼圆" size="2" class="gmail_msg">詹石岩</font></div></font></span></div></div><div class="gmail_msg"> </div><br class="gmail_msg">_______________________________________________<br class="gmail_msg">
cfe-dev mailing list<br class="gmail_msg">
<a href="mailto:cfe-dev@lists.llvm.org" class="gmail_msg" target="_blank">cfe-dev@lists.llvm.org</a><br class="gmail_msg">
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" class="gmail_msg" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br class="gmail_msg">
<br class="gmail_msg"></blockquote></div><br class="gmail_msg"></div>
_______________________________________________<br class="gmail_msg">
cfe-dev mailing list<br class="gmail_msg">
<a href="mailto:cfe-dev@lists.llvm.org" class="gmail_msg" target="_blank">cfe-dev@lists.llvm.org</a><br class="gmail_msg">
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" class="gmail_msg" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br class="gmail_msg">
</blockquote></div>