<div dir="ltr">Hi Piotr,<div><br></div><div>Thanks. Yeah, it seemed a little weird, but it was what got me closest. I found out that the matcher I supplied here was working for clang-query 3.8.1. I'm working on a clang-tidy module for 4.0.0 - it's not working there. </div><div><br></div><div>Could you elaborate on the "onImplicitObjectArgument"? There is no document on it on the clang page. So I wouldn't know how it works or what it does.</div><div><br></div><div>Best regards,</div><div>Mads Ravn</div></div><br><div class="gmail_quote"><div dir="ltr">On Mon, Nov 28, 2016 at 10:50 PM Piotr Padlewski <<a href="mailto:piotr.padlewski@gmail.com">piotr.padlewski@gmail.com</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"><font face="monospace, monospace" class="gmail_msg">Hi Mads,</font></div><div class="gmail_msg"><font face="arial, helvetica, sans-serif" class="gmail_msg">I formatted your matcher a little bit just to understand it:</font></div></div><div dir="ltr" class="gmail_msg"><div class="gmail_msg"><font face="monospace, monospace" class="gmail_msg"><br class="gmail_msg"></font></div><div class="gmail_msg"><font face="monospace, monospace" class="gmail_msg"><span style="font-size:12.8px" class="gmail_msg">ifStmt(hasCondition(</span><span style="font-size:12.8px" class="gmail_msg">implicitCastExpr(</span><span style="font-size:12.8px" class="gmail_msg">hasImplicitDestinationType(</span><span style="font-size:12.8px" class="gmail_msg">isInteger()), </span></font></div><div class="gmail_msg"><font face="monospace, monospace" class="gmail_msg"><span style="font-size:12.8px" class="gmail_msg"> has(cxxMemberCallExpr(callee(</span><span style="font-size:12.8px" class="gmail_msg">cxxMethodDecl(hasName("</span><span style="font-size:12.8px" class="gmail_msg">compare"))),</span></font></div><div class="gmail_msg"><font face="monospace, monospace" class="gmail_msg"><span style="font-size:12.8px" class="gmail_msg"> hasArgument(0, declRefExpr().bind("str2")), </span></font></div><div class="gmail_msg"><font face="monospace, monospace" class="gmail_msg"><span style="font-size:12.8px" class="gmail_msg"> callee(memberExpr(has(</span><span style="font-size:12.8px" class="gmail_msg">declRefExpr().bind("str1")))))</span><span style="font-size:12.8px" class="gmail_msg">)))).bind("case1")</span><br class="gmail_msg"></font></div><div class="gmail_msg"><br class="gmail_msg"></div></div><div dir="ltr" class="gmail_msg"><div class="gmail_msg">And this is the AST part that we care about</div><div class="gmail_msg"><div class="gmail_msg"><font face="monospace, monospace" class="gmail_msg">|-IfStmt 0x7fba9625f5e8 <line:8:5, line:10:5></font></div><div class="gmail_msg"><font face="monospace, monospace" class="gmail_msg"> | |-<<<NULL>>></font></div><div class="gmail_msg"><font face="monospace, monospace" class="gmail_msg"> | |-<<<NULL>>></font></div><div class="gmail_msg"><font face="monospace, monospace" class="gmail_msg"> | |-ImplicitCastExpr 0x7fba96258a80 <line:8:8, col:25> '_Bool' <IntegralToBoolean></font></div><div class="gmail_msg"><font face="monospace, monospace" class="gmail_msg"> | | `-CXXMemberCallExpr 0x7fba96258a20 <col:8, col:25> 'int'</font></div><div class="gmail_msg"><font face="monospace, monospace" class="gmail_msg"> | | |-MemberExpr 0x7fba962589e8 <col:8, col:13> '<bound member function type>' .compare 0x7fba956ba078</font></div><div class="gmail_msg"><font face="monospace, monospace" class="gmail_msg"> | | | `-ImplicitCastExpr 0x7fba96258a50 <col:8> 'const class std::__1::basic_string<char>' lvalue <NoOp></font></div><div class="gmail_msg"><font face="monospace, monospace" class="gmail_msg"> | | | `-DeclRefExpr 0x7fba962588e0 <col:8> 'std::string':'class std::__1::basic_string<char>' lvalue Var 0x7fba962585b8 'str1' 'std::string':'class std::__1::basic_string<char>'</font></div><div class="gmail_msg"><font face="monospace, monospace" class="gmail_msg"> | | `-ImplicitCastExpr 0x7fba96258a68 <col:21> 'const class std::__1::basic_string<char>' lvalue <NoOp></font></div><div class="gmail_msg"><font face="monospace, monospace" class="gmail_msg"> | | `-DeclRefExpr 0x7fba962589b0 <col:21> 'std::string':'class std::__1::basic_string<char>' lvalue Var 0x7fba96258770 'str2' 'std::string':'class std::__1::basic_string<char>'</font></div></div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">The callee called twice seems weird. Try to replace second one with "onImplicitObjectArgument", or "on", or in the worst case - "has" (which would not be totally valid).</div></div><div dir="ltr" class="gmail_msg"><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Piotr.</div></div><div class="gmail_extra gmail_msg"><br class="gmail_msg"><div class="gmail_quote gmail_msg"><a href="tel:20%2016%2011%2028" value="+4520161128" class="gmail_msg" target="_blank">2016-11-28</a> 9:06 GMT+01:00 Mads Ravn <span dir="ltr" class="gmail_msg"><<a href="mailto:madsravn@gmail.com" class="gmail_msg" target="_blank">madsravn@gmail.com</a>></span>:<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 dir="ltr" class="gmail_msg">Hi Piotr,<div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">I think I found a working matcher: match ifStmt(hasCondition(implicitCastExpr(hasImplicitDestinationType(isInteger()), has(cxxMemberCallExpr(callee(cxxMethodDecl(hasName("compare"))), hasArgument(0, declRefExpr().bind("str2")), callee(memberExpr(has(declRefExpr().bind("str1"))))))))).bind("case1")</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">This one bind to both str1 and str2 in str1.compare(str2). I have included a code segment below. I have attached a screenshot of this matcher working from clang-query.</div><div class="gmail_msg">HOWEVER - when I try to use the matcher in clang-tidy it will not work. It is because of the <span style="line-height:1.5" class="gmail_msg">callee(memberExpr(has(declRefExpr().bind("str1")))) part of the matcher. If I remove that, I can match on the str1.compare(str2) from the code. But I need to bind str1 as well to test if it is a string.</span></div><div class="gmail_msg"><span style="line-height:1.5" class="gmail_msg"><br class="gmail_msg"></span></div><div class="gmail_msg"><span style="line-height:1.5" class="gmail_msg">Do you have any idea why a matcher would work in clang-query, but not in clang-tidy? It's the same piece of code it is working on. Is there something wrong with my matcher (undefined behavior or something)?</span></div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Code: </div><div class="gmail_msg"><div class="gmail_msg">#include <iostream></div><div class="gmail_msg">#include <string></div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">int main() {</div><div class="gmail_msg"> std::string str1{"aa"};</div><div class="gmail_msg"> std::string str2{"bb"};</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"> if(str1.compare(str2)) {</div><div class="gmail_msg"> std::cout << "Strings not equal" << std::endl;</div><div class="gmail_msg"> }</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"> return 0;</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">}</div></div><div class="gmail_msg"><div class="m_8737829650065248621h5 gmail_msg"><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><br class="gmail_msg"></div><br class="gmail_msg"><div class="gmail_quote gmail_msg"><div dir="ltr" class="gmail_msg">On Sun, Nov 27, 2016 at 10:39 PM Piotr Padlewski <<a href="mailto:piotr.padlewski@gmail.com" class="gmail_msg" target="_blank">piotr.padlewski@gmail.com</a>> wrote:<br class="gmail_msg"></div><blockquote class="gmail_quote gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="m_8737829650065248621m_-6654910606099621339gmail_msg gmail_msg">Sorry for writing 3 emails,<div class="m_8737829650065248621m_-6654910606099621339gmail_msg gmail_msg">I looked into <a href="http://clang.llvm.org/docs/LibASTMatchersReference.html" class="m_8737829650065248621m_-6654910606099621339gmail_msg gmail_msg" target="_blank">http://clang.llvm.org/docs/LibASTMatchersReference.html</a>? and it seems that matcher </div><div class="m_8737829650065248621m_-6654910606099621339gmail_msg gmail_msg">on : </div><table style="font-family:"lucida grande","lucida sans unicode",arial,verdana,helvetica,sans-serif" class="m_8737829650065248621m_-6654910606099621339gmail_msg gmail_msg"><tbody class="m_8737829650065248621m_-6654910606099621339gmail_msg gmail_msg"><tr style="vertical-align:top" class="m_8737829650065248621m_-6654910606099621339gmail_msg gmail_msg"><td style="padding:0.33em" class="m_8737829650065248621m_-6654910606099621339gmail_msg gmail_msg">Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXMemberCallExpr.html" class="m_8737829650065248621m_-6654910606099621339gmail_msg gmail_msg" target="_blank">CXXMemberCallExpr</a>></td><td class="m_8737829650065248621m_-6654910606099621339m_-7096765933453598891gmail-name m_8737829650065248621m_-6654910606099621339gmail_msg gmail_msg" style="padding:0.33em"><font color="#1155cc" class="m_8737829650065248621m_-6654910606099621339gmail_msg gmail_msg">-></font></td><td style="padding:0.33em" class="m_8737829650065248621m_-6654910606099621339gmail_msg gmail_msg">Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html" class="m_8737829650065248621m_-6654910606099621339gmail_msg gmail_msg" target="_blank">Expr</a>> InnerMatcher</td></tr></tbody></table><br class="m_8737829650065248621m_-6654910606099621339gmail_msg gmail_msg"><div class="m_8737829650065248621m_-6654910606099621339gmail_msg gmail_msg">would be my candidate to check. If it won't gonna work then send the test and AST dump and I will try to help.</div></div><div dir="ltr" class="m_8737829650065248621m_-6654910606099621339gmail_msg gmail_msg"><div class="m_8737829650065248621m_-6654910606099621339gmail_msg gmail_msg"><br class="m_8737829650065248621m_-6654910606099621339gmail_msg gmail_msg"></div><div class="m_8737829650065248621m_-6654910606099621339gmail_msg gmail_msg">Piotr</div></div><div class="gmail_extra m_8737829650065248621m_-6654910606099621339gmail_msg gmail_msg"><br class="m_8737829650065248621m_-6654910606099621339gmail_msg gmail_msg"><div class="gmail_quote m_8737829650065248621m_-6654910606099621339gmail_msg gmail_msg">2016-11-27 22:35 GMT+01:00 Piotr Padlewski <span dir="ltr" class="m_8737829650065248621m_-6654910606099621339gmail_msg gmail_msg"><<a href="mailto:piotr.padlewski@gmail.com" class="m_8737829650065248621m_-6654910606099621339gmail_msg gmail_msg" target="_blank">piotr.padlewski@gmail.com</a>></span>:<br class="m_8737829650065248621m_-6654910606099621339gmail_msg gmail_msg"><blockquote class="gmail_quote m_8737829650065248621m_-6654910606099621339gmail_msg gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="m_8737829650065248621m_-6654910606099621339gmail_msg gmail_msg">Adding cfe-dev, because it is related to clang, not LLVM.</div><div class="m_8737829650065248621m_-6654910606099621339m_-7096765933453598891HOEnZb m_8737829650065248621m_-6654910606099621339gmail_msg gmail_msg"><div class="m_8737829650065248621m_-6654910606099621339m_-7096765933453598891h5 m_8737829650065248621m_-6654910606099621339gmail_msg gmail_msg"><div class="gmail_extra m_8737829650065248621m_-6654910606099621339gmail_msg gmail_msg"><br class="m_8737829650065248621m_-6654910606099621339gmail_msg gmail_msg"><div class="gmail_quote m_8737829650065248621m_-6654910606099621339gmail_msg gmail_msg">2016-11-27 22:34 GMT+01:00 Piotr Padlewski <span dir="ltr" class="m_8737829650065248621m_-6654910606099621339gmail_msg gmail_msg"><<a href="mailto:piotr.padlewski@gmail.com" class="m_8737829650065248621m_-6654910606099621339gmail_msg gmail_msg" target="_blank">piotr.padlewski@gmail.com</a>></span>:<br class="m_8737829650065248621m_-6654910606099621339gmail_msg gmail_msg"><blockquote class="gmail_quote m_8737829650065248621m_-6654910606099621339gmail_msg gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="m_8737829650065248621m_-6654910606099621339gmail_msg gmail_msg">Hi Mads,<div class="m_8737829650065248621m_-6654910606099621339gmail_msg gmail_msg">Can you provide the code that you run clang-query on, or at least AST for the fragment you want to match?</div><div class="m_8737829650065248621m_-6654910606099621339gmail_msg gmail_msg"><br class="m_8737829650065248621m_-6654910606099621339gmail_msg gmail_msg"></div><div class="m_8737829650065248621m_-6654910606099621339gmail_msg gmail_msg">Piotr</div></div><div class="gmail_extra m_8737829650065248621m_-6654910606099621339gmail_msg gmail_msg"><br class="m_8737829650065248621m_-6654910606099621339gmail_msg gmail_msg"><div class="gmail_quote m_8737829650065248621m_-6654910606099621339gmail_msg gmail_msg"><div class="m_8737829650065248621m_-6654910606099621339gmail_msg gmail_msg"><div class="m_8737829650065248621m_-6654910606099621339m_-7096765933453598891m_-1636274675611907480h5 m_8737829650065248621m_-6654910606099621339gmail_msg gmail_msg">2016-11-26 22:27 GMT+01:00 Mads Ravn via llvm-dev <span dir="ltr" class="m_8737829650065248621m_-6654910606099621339gmail_msg gmail_msg"><<a href="mailto:llvm-dev@lists.llvm.org" class="m_8737829650065248621m_-6654910606099621339gmail_msg gmail_msg" target="_blank">llvm-dev@lists.llvm.org</a>></span>:<br class="m_8737829650065248621m_-6654910606099621339gmail_msg gmail_msg"></div></div><blockquote class="gmail_quote m_8737829650065248621m_-6654910606099621339gmail_msg gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="m_8737829650065248621m_-6654910606099621339gmail_msg gmail_msg"><div class="m_8737829650065248621m_-6654910606099621339m_-7096765933453598891m_-1636274675611907480h5 m_8737829650065248621m_-6654910606099621339gmail_msg gmail_msg"><div dir="ltr" class="m_8737829650065248621m_-6654910606099621339gmail_msg gmail_msg">Hi,<div class="m_8737829650065248621m_-6654910606099621339gmail_msg gmail_msg"><br class="m_8737829650065248621m_-6654910606099621339gmail_msg gmail_msg"></div><div class="m_8737829650065248621m_-6654910606099621339gmail_msg gmail_msg">Hope this is the right channel for this question. I am trying to make an ast matcher for clang-tidy to find str1.compare(str2), where both str1 and str2 are std::string. I have this so far: <a href="http://i.imgur.com/sUma9WC.png" class="m_8737829650065248621m_-6654910606099621339gmail_msg gmail_msg" target="_blank">http://i.imgur.com/sUma9WC.png</a> . But I am having a hard time finding a way to bind an id to the str1 part of the expression.</div><div class="m_8737829650065248621m_-6654910606099621339gmail_msg gmail_msg"><br class="m_8737829650065248621m_-6654910606099621339gmail_msg gmail_msg"></div><div class="m_8737829650065248621m_-6654910606099621339gmail_msg gmail_msg">Can anyone help me out with an idea?</div><div class="m_8737829650065248621m_-6654910606099621339gmail_msg gmail_msg"><br class="m_8737829650065248621m_-6654910606099621339gmail_msg gmail_msg"></div><div class="m_8737829650065248621m_-6654910606099621339gmail_msg gmail_msg">Best regards,</div><div class="m_8737829650065248621m_-6654910606099621339gmail_msg gmail_msg">Mads Ravn</div></div>
<br class="m_8737829650065248621m_-6654910606099621339gmail_msg gmail_msg"></div></div>_______________________________________________<br class="m_8737829650065248621m_-6654910606099621339gmail_msg gmail_msg">
LLVM Developers mailing list<br class="m_8737829650065248621m_-6654910606099621339gmail_msg gmail_msg">
<a href="mailto:llvm-dev@lists.llvm.org" class="m_8737829650065248621m_-6654910606099621339gmail_msg gmail_msg" target="_blank">llvm-dev@lists.llvm.org</a><br class="m_8737829650065248621m_-6654910606099621339gmail_msg gmail_msg">
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" class="m_8737829650065248621m_-6654910606099621339gmail_msg gmail_msg" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br class="m_8737829650065248621m_-6654910606099621339gmail_msg gmail_msg">
<br class="m_8737829650065248621m_-6654910606099621339gmail_msg gmail_msg"></blockquote></div><br class="m_8737829650065248621m_-6654910606099621339gmail_msg gmail_msg"></div>
</blockquote></div><br class="m_8737829650065248621m_-6654910606099621339gmail_msg gmail_msg"></div>
</div></div></blockquote></div><br class="m_8737829650065248621m_-6654910606099621339gmail_msg gmail_msg"></div>
</blockquote></div></div></div></div>
</blockquote></div><br class="gmail_msg"></div>
</blockquote></div>