<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Nov 20, 2014 at 4:46 AM, Manuel Klimek <span dir="ltr"><<a href="mailto:klimek@google.com" target="_blank">klimek@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="gmail_quote"><div><div class="h5">On Thu Nov 20 2014 at 1:43:48 PM Georg Altmann <<a href="mailto:georg.altmann@informatik.stud.uni-erlangen.de" target="_blank">georg.altmann@informatik.stud.uni-erlangen.de</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On 20.11.2014 10:25, Manuel Klimek wrote:<br>
> On Wed Nov 19 2014 at 3:38:44 PM Georg Altmann<br>
> <<a href="mailto:georg.altmann@informatik.stud.uni-erlangen.de" target="_blank">georg.altmann@informatik.<u></u>stud.uni-erlangen.de</a><br>
> <mailto:<a href="mailto:georg.altmann@informatik.stud.uni-erlangen.de" target="_blank">georg.altmann@<u></u>informatik.stud.uni-erlangen.<u></u>de</a>>> wrote:<br>
><br>
>     Thank you for the quick reply.<br>
><br>
>     I found a partial solution to my problem. I dug down into the AST<br>
>     matching code and noticed RecursiveASTVisitor did not recurse into<br>
>     CapturedStmt in CilkSpawnDecl. So I did the patch<br>
><br>
><br>
>     diff --git a/include/clang/AST/__<u></u>RecursiveASTVisitor.h<br>
>     b/include/clang/AST/__<u></u>RecursiveASTVisitor.h<br>
>     index 35eec69..a16e772 100755<br>
>     --- a/include/clang/AST/__<u></u>RecursiveASTVisitor.h<br>
>     +++ b/include/clang/AST/__<u></u>RecursiveASTVisitor.h<br>
>     @@ -1305,6 +1305,7 @@ DEF_TRAVERSE_DECL(__<u></u>CapturedDecl, {<br>
>        })<br>
><br>
>      DEF_TRAVERSE_DECL(__<u></u>CilkSpawnDecl, {<br>
>     +    TRY_TO(TraverseStmt(D->__<u></u>getCapturedStmt()));<br>
>        })<br>
><br>
>      DEF_TRAVERSE_DECL(EmptyDecl, { })<br>
><br>
><br>
>     Again, this is what I want to match:<br>
>     The AST:<br>
>     |-CompoundStmt<br>
>     | `-CilkSpawnExpr<br>
>     |   |-CilkSpawnDecl<br>
>     |   | `-CapturedStmt<br>
>     |   |   |-CapturedDecl<br>
>     |   |   | `-ImplicitParamDecl<br>
>     |   |   |-ExprWithCleanups<br>
>     |   |   | `-CallExpr<br>
>     --------------^ this guy<br>
><br>
><br>
>     After the patch, these match now:<br>
><br>
>     // 1) matches<br>
>     compoundStmt(<br>
>       has(cilkSpawnExpr(<br>
>        has(cilkSpawnDecl(<br>
>          has(capturedStmt()))))))<br>
><br>
>     // 2) matches and binds<br>
>     compoundStmt(<br>
>       has(cilkSpawnExpr(<br>
>         has(cilkSpawnDecl(<br>
>           has(capturedStmt(<br>
>             hasDescendant(__<u></u>exprWithCleanups(<br>
>               has(callExpr().bind("callExpr"<u></u>__))))))))))<br>
><br>
><br>
>     However this doesn't match, while it should IMHO.<br>
><br>
>     // 3) does not match<br>
>     compoundStmt(<br>
>       has(cilkSpawnExpr(<br>
>         has(cilkSpawnDecl(<br>
>             has(capturedStmt(<br>
>                 has(exprWithCleanups())))))))<br>
><br>
><br>
> Which one in this chain is the one that doesn't match? (remove inner<br>
> ones until it matches, send result).<br>
<br>
<br>
These match:<br>
<br>
compoundStmt(<br>
  has(cilkSpawnExpr(<br>
    has(cilkSpawnDecl(<br>
      has(capturedStmt()))))))<br>
<br>
compoundStmt(<br>
  has(cilkSpawnExpr(<br>
    has(cilkSpawnDecl(<br>
      has(capturedStmt(<br>
        has(decl()))))))))<br>
<br>
compoundStmt(<br>
  has(cilkSpawnExpr(<br>
    has(cilkSpawnDecl(<br>
      has(capturedStmt(<br>
        // for some reason has() does not work here<br>
        hasDescendant(<u></u>exprWithCleanups(<br>
          has(callExpr().bind("callExpr"<u></u>)))))))))))<br>
<br>
<br>
None of these match:<br>
<br>
compoundStmt(<br>
  has(cilkSpawnExpr(<br>
    has(cilkSpawnDecl(<br>
      has(capturedStmt(<br>
        has(exprWithCleanups()))))))))<br>
<br>
compoundStmt(<br>
  has(cilkSpawnExpr(<br>
    has(cilkSpawnDecl(<br>
      has(capturedStmt(<br>
        has(expr()))))))))<br>
<br>
compoundStmt(<br>
  has(cilkSpawnExpr(<br>
    has(cilkSpawnDecl(<br>
      has(capturedStmt(<br>
        has(stmt()))))))))<br>
<br>
compoundStmt(<br>
  has(cilkSpawnExpr(<br>
    has(cilkSpawnDecl(<br>
      has(capturedStmt(<br>
        has(decl()))))))))<br>
<br>
To me this looks like either<br>
a) the ast-dump is incorrect and ExprWithCleanups is not a direct child<br>
of CapturedStmt<br>
or<br>
b) there is a bug with CapturedStmt in the ast matching code /<br>
RecursiveASTVisitor which makes ExprWithCleanups being found as<br>
descendant but not as direct child.<br>
<br>
Maybe a test-case against vanilla clang would be helpful? However I<br>
don't know how to reproduce the AST without the cilk extensions.<br></blockquote><div><br></div></div></div><div>The problem is that the RecursiveASTVisitor and the -ast-dump logic use completely different code paths... I still think this is probably a bug in one of the two.</div><div>+richardsmith, who knows more about this...</div></div></blockquote><div><br></div><div>-ast-dump has no custom logic for CapturedStmt, so I'm surprised you're getting the dump you provide above. I don't see that with clang trunk. Perhaps this is something that the cilk folks changed.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Regards,<br>
Georg<br>
<br>
<br>
</blockquote></div>
</blockquote></div><br></div></div>