[cfe-dev] AST Matcher for Decl subclass CilkSpawnDecl
Richard Smith
richard at metafoo.co.uk
Thu Nov 20 20:55:50 PST 2014
On Thu, Nov 20, 2014 at 4:46 AM, Manuel Klimek <klimek at google.com> wrote:
> On Thu Nov 20 2014 at 1:43:48 PM Georg Altmann <
> georg.altmann at informatik.stud.uni-erlangen.de> wrote:
>
>> On 20.11.2014 10:25, Manuel Klimek wrote:
>> > On Wed Nov 19 2014 at 3:38:44 PM Georg Altmann
>> > <georg.altmann at informatik.stud.uni-erlangen.de
>> > <mailto:georg.altmann at informatik.stud.uni-erlangen.de>> wrote:
>> >
>> > Thank you for the quick reply.
>> >
>> > I found a partial solution to my problem. I dug down into the AST
>> > matching code and noticed RecursiveASTVisitor did not recurse into
>> > CapturedStmt in CilkSpawnDecl. So I did the patch
>> >
>> >
>> > diff --git a/include/clang/AST/__RecursiveASTVisitor.h
>> > b/include/clang/AST/__RecursiveASTVisitor.h
>> > index 35eec69..a16e772 100755
>> > --- a/include/clang/AST/__RecursiveASTVisitor.h
>> > +++ b/include/clang/AST/__RecursiveASTVisitor.h
>> > @@ -1305,6 +1305,7 @@ DEF_TRAVERSE_DECL(__CapturedDecl, {
>> > })
>> >
>> > DEF_TRAVERSE_DECL(__CilkSpawnDecl, {
>> > + TRY_TO(TraverseStmt(D->__getCapturedStmt()));
>> > })
>> >
>> > DEF_TRAVERSE_DECL(EmptyDecl, { })
>> >
>> >
>> > Again, this is what I want to match:
>> > The AST:
>> > |-CompoundStmt
>> > | `-CilkSpawnExpr
>> > | |-CilkSpawnDecl
>> > | | `-CapturedStmt
>> > | | |-CapturedDecl
>> > | | | `-ImplicitParamDecl
>> > | | |-ExprWithCleanups
>> > | | | `-CallExpr
>> > --------------^ this guy
>> >
>> >
>> > After the patch, these match now:
>> >
>> > // 1) matches
>> > compoundStmt(
>> > has(cilkSpawnExpr(
>> > has(cilkSpawnDecl(
>> > has(capturedStmt()))))))
>> >
>> > // 2) matches and binds
>> > compoundStmt(
>> > has(cilkSpawnExpr(
>> > has(cilkSpawnDecl(
>> > has(capturedStmt(
>> > hasDescendant(__exprWithCleanups(
>> > has(callExpr().bind("callExpr"__))))))))))
>> >
>> >
>> > However this doesn't match, while it should IMHO.
>> >
>> > // 3) does not match
>> > compoundStmt(
>> > has(cilkSpawnExpr(
>> > has(cilkSpawnDecl(
>> > has(capturedStmt(
>> > has(exprWithCleanups())))))))
>> >
>> >
>> > Which one in this chain is the one that doesn't match? (remove inner
>> > ones until it matches, send result).
>>
>>
>> These match:
>>
>> compoundStmt(
>> has(cilkSpawnExpr(
>> has(cilkSpawnDecl(
>> has(capturedStmt()))))))
>>
>> compoundStmt(
>> has(cilkSpawnExpr(
>> has(cilkSpawnDecl(
>> has(capturedStmt(
>> has(decl()))))))))
>>
>> compoundStmt(
>> has(cilkSpawnExpr(
>> has(cilkSpawnDecl(
>> has(capturedStmt(
>> // for some reason has() does not work here
>> hasDescendant(exprWithCleanups(
>> has(callExpr().bind("callExpr")))))))))))
>>
>>
>> None of these match:
>>
>> compoundStmt(
>> has(cilkSpawnExpr(
>> has(cilkSpawnDecl(
>> has(capturedStmt(
>> has(exprWithCleanups()))))))))
>>
>> compoundStmt(
>> has(cilkSpawnExpr(
>> has(cilkSpawnDecl(
>> has(capturedStmt(
>> has(expr()))))))))
>>
>> compoundStmt(
>> has(cilkSpawnExpr(
>> has(cilkSpawnDecl(
>> has(capturedStmt(
>> has(stmt()))))))))
>>
>> compoundStmt(
>> has(cilkSpawnExpr(
>> has(cilkSpawnDecl(
>> has(capturedStmt(
>> has(decl()))))))))
>>
>> To me this looks like either
>> a) the ast-dump is incorrect and ExprWithCleanups is not a direct child
>> of CapturedStmt
>> or
>> b) there is a bug with CapturedStmt in the ast matching code /
>> RecursiveASTVisitor which makes ExprWithCleanups being found as
>> descendant but not as direct child.
>>
>> Maybe a test-case against vanilla clang would be helpful? However I
>> don't know how to reproduce the AST without the cilk extensions.
>>
>
> 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.
> +richardsmith, who knows more about this...
>
-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.
> Regards,
>> Georg
>>
>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20141120/4130c511/attachment.html>
More information about the cfe-dev
mailing list