[cfe-dev] clang-qurery and compiler reacting differently to a matcher

Piotr Padlewski via cfe-dev cfe-dev at lists.llvm.org
Fri Jul 1 09:23:19 PDT 2016


CC @klimek @alexfh @djasper

There are some differences in behaviour of clang-query and ast matchers in
code. I also don't know why and I would like to know.

Piotr

On Fri, Jul 1, 2016 at 6:15 AM, Farzad Sadeghi via cfe-dev <
cfe-dev at lists.llvm.org> wrote:

> i have the following ASTMatcher:
>
> `functionDecl(forEachDescendant(expr(allOf(forEachDescendant(callExpr(anyOf(hasDescendant(declRefExpr(to(varDecl(anything()))).bind("args")),
> unless(hasDescendant(declRefExpr(to(varDecl(anything()))))))
>
> ).bind("callee")),unless(hasAncestor(binaryOperator())))).bind("expression"))).bind("scopeDaddy")`.
> it compiles and works fine both after building and running it and also
> in clang-query.
> i needed to make some changes to it so i wrote this one:
>
> `functionDecl(forEachDescendant(anyOf(expr(allOf(forEachDescendant(callExpr(anyOf(hasDescendant(declRefExpr(to(varDecl(anything()))).bind("args")),
> unless(hasDescendant(declRefExpr(to(varDecl(anything()))))))
>
> ).bind("callee")),unless(hasAncestor(binaryOperator())))).bind("expression"),
>
> callExpr(unless(hasAncestor(expr()))).bind("orphancall")))).bind("scopeDaddy")`
> when i run it in clang-query it runs without a problem but when i put
> that in my code and try to compile it, the compiler returns this:
>
> -----------------------------------------------------------------------------------------------------------------------------
> tokenizer.cpp: In constructor
> ‘TokenizerASTConsumer::TokenizerASTConsumer(clang::Rewriter&)’:
> tokenizer.cpp:544:348: error: no match for call to ‘(const
>
> clang::ast_matchers::internal::ArgumentAdaptingMatcherFunc<clang::ast_matchers::internal::ForEachDescendantMatcher>)
>
> (clang::ast_matchers::internal::VariadicOperatorMatcher<clang::ast_matchers::internal::Matcher<clang::Stmt>,
> clang::ast_matchers::internal::BindableMatcher<clang::Stmt> >)’
>  Decl(anything()))))))
>
> ).bind("callee")),unless(hasAncestor(binaryOperator())))).bind("expression"),
> callExpr(unless(hasAncestor(expr())))))).bind("sc
>
>                                                                     ^
> In file included from
> /usr/local/include/clang/ASTMatchers/ASTMatchers.h:52:0,
>                  from tokenizer.cpp:15:
> /usr/local/include/clang/ASTMatchers/ASTMatchersInternal.h:1043:14:
> note: candidate: template<class T>
>
> clang::ast_matchers::internal::ArgumentAdaptingMatcherFunc<ArgumentAdapterT,
> FromTypes, ToTypes>::Adaptor<T>
>
> clang::ast_matchers::internal::ArgumentAdaptingMatcherFunc<ArgumentAdapterT,
> FromTypes, ToTypes>::operator()(const
> clang::ast_matchers::internal::Matcher<From>&) const [with T = T;
> ArgumentAdapterT =
> clang::ast_matchers::internal::ForEachDescendantMatcher; FromTypes =
> clang::ast_matchers::internal::TypeList<clang::Decl, clang::Stmt,
> clang::NestedNameSpecifier, clang::NestedNameSpecifierLoc,
> clang::QualType, clang::Type, clang::TypeLoc,
> clang::CXXCtorInitializer>; ToTypes =
> clang::ast_matchers::internal::TypeList<clang::Decl, clang::Stmt,
> clang::NestedNameSpecifier, clang::NestedNameSpecifierLoc,
> clang::TypeLoc, clang::QualType>]
>    Adaptor<T> operator()(const Matcher<T> &InnerMatcher) const {
>               ^
> /usr/local/include/clang/ASTMatchers/ASTMatchersInternal.h:1043:14:
> note:   template argument deduction/substitution failed:
> tokenizer.cpp:544:348: note:
>
> ‘clang::ast_matchers::internal::VariadicOperatorMatcher<clang::ast_matchers::internal::Matcher<clang::Stmt>,
> clang::ast_matchers::internal::BindableMatcher<clang::Stmt> >’ is not
> derived from ‘const clang::ast_matchers::internal::Matcher<T>’
>  Decl(anything()))))))
>
> ).bind("callee")),unless(hasAncestor(binaryOperator())))).bind("expression"),
> callExpr(unless(hasAncestor(expr())))))).bind("sc
>
>  ------------------------------------------------------------------------------------------------------------------------------
> I've built my llvm and clang libraries from the SVN version 3.9.0
> using g++ and use g++ 5.3.1 to compile this code  .
> is the matcher wrong and clang-query fails to see that(even though it
> acts exactly as i intended it to) or it's something else?
>
>
>
> --
> Farzad Sadeghi
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20160701/0c10af7d/attachment.html>


More information about the cfe-dev mailing list