[cfe-dev] AST Matcher for Decl subclass CilkSpawnDecl
Georg Altmann
georg.altmann at informatik.stud.uni-erlangen.de
Thu Nov 20 04:49:28 PST 2014
On 20.11.2014 13:46, Manuel Klimek wrote:
> On Thu Nov 20 2014 at 1:43:48 PM Georg Altmann
> <georg.altmann at informatik.stud.uni-erlangen.de
> <mailto: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>
> > <mailto: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...
Just to prevent any duplicate work: remember cilkplus is based on clang
3.4. This might already be fixed in current clang.
I might dig into this deeper later. For now the hasDescendant match is
good enough for me at this point.
Regards,
Georg
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: OpenPGP digital signature
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20141120/86f69353/attachment.sig>
More information about the cfe-dev
mailing list