[cfe-dev] clang-qurery and compiler reacting differently to a matcher
Farzad Sadeghi via cfe-dev
cfe-dev at lists.llvm.org
Mon Jul 4 10:15:39 PDT 2016
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?
On 7/4/16, Manuel Klimek <klimek at google.com> wrote:
> On Mon, Jul 4, 2016 at 12:09 PM Farzad Sadeghi <thabogre at gmail.com> wrote:
>
>> How can we do that?
>> I'm new to llvm so I need some tips/hints to be able to help.
>>
>
> First, I'd try it with a newer GCC - perhaps this was a GCC bug that is
> already fixed.
>
>
>>
>> On 7/4/16, Manuel Klimek <klimek at google.com> wrote:
>> > (larger list back in, please reply-to all, not just me, thanks! :)
>> >
>> > On Mon, Jul 4, 2016 at 11:44 AM Farzad Sadeghi <thabogre at gmail.com>
>> wrote:
>> >
>> >> i just checked the matcher using clang++ and llvm-devel and
>> >> clang-devel that i just got from Fedora's repository (3.7.0.). The
>> >> problem is when the four special Narrowing matchers (anyOf, allOf,
>> >> anything, unless) are passed as argument to `forEachDescendant`.
>> >>
>> >
>> > Previously there were limits with return type deduction, which we do
>> > with
>> > expression templates that have a templated conversion operator. I think
>> Sam
>> > (cc'ed) fixed that at some point. If this doesn't work with gcc, it's
>> > either a clang or gcc bug. We need to reduce this in a way that doesn't
>> > require the AST matchers.
>> >
>> >
>> >>
>> >> On 7/4/16, Manuel Klimek <klimek at google.com> wrote:
>> >> > (cfe-dev back in)
>> >> >
>> >> > On Mon, Jul 4, 2016 at 10:26 AM Farzad Sadeghi <thabogre at gmail.com>
>> >> wrote:
>> >> >
>> >> >> Are you using clang as the compiler?
>> >> >> I'm using g++ and the library built using g++. maybe that's what's
>> >> >> causing
>> >> >> this.
>> >> >>
>> >> >
>> >> > Yea, I'm using a recent enough clang. My system GCC is unfortunately
>> >> super
>> >> > old (ubuntu LTS). The interesting part would be to reduce it so we
>> >> > can
>> >> see
>> >> > which compiler has the bug.
>> >> >
>> >> >
>> >> > On 7/4/16, Manuel Klimek <klimek at google.com> wrote:
>> >> >> > On Fri, Jul 1, 2016 at 3:15 PM 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?
>> >> >> >>
>> >> >> >
>> >> >> > Hrm, for me with clang trunk this matcher compiles just fine.
>> >> >> >
>> >> >> >
>> >> >> >
>> >> >> >>
>> >> >> >>
>> >> >> >>
>> >> >> >> --
>> >> >> >> Farzad Sadeghi
>> >> >> >> _______________________________________________
>> >> >> >> cfe-dev mailing list
>> >> >> >> cfe-dev at lists.llvm.org
>> >> >> >> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>> >> >> >>
>> >> >> >
>> >> >>
>> >> >>
>> >> >> --
>> >> >> Farzad Sadeghi
>> >> >>
>> >> >
>> >>
>> >>
>> >> --
>> >> Farzad Sadeghi
>> >>
>> >
>>
>>
>> --
>> Farzad Sadeghi
>>
>
--
Farzad Sadeghi
More information about the cfe-dev
mailing list