[cfe-dev] matcher acting wierd,imho

Farzad Sadeghi via cfe-dev cfe-dev at lists.llvm.org
Tue Nov 8 10:02:52 PST 2016


I'm not sure if this is significant  but like Malcolm said the
problem's probably `hasAncestor`.
this is the source code:
void myfunc (void)
{
        int a = 0U;
        int b = 10U;

        if (a == b)
        {
                a++;
        }
        else if (a > b )
        {
                b++;
        }

}
this matcher "ifStmt( allOf( hasDescendant(ifStmt()),
hasElse(anything()) ) )" returns:
/home/bloodstalker/devi/hell1/test3.c:6:9: note: "root" binds here
        if (a == b)
        ^~~~~~~~~~~
1 match.
but this matcher "ifStmt( allOf( hasDescendant(ifStmt()),
hasElse(anything()) ,unless(hasAncestor(ifStmt()))))" matches nothing.
clearly the first "if" doesnt have an ifStmt ancestor, so
hasAncestor(ifStmt()) should be true and it should still match the
first "if".

On 11/8/16, Manuel Klimek <klimek at google.com> wrote:
> Sam, any ideas whether this might be a dynamic matcher problem?
>
> On Tue, Nov 8, 2016 at 7:48 AM Aaron Ballman <aaron at aaronballman.com>
> wrote:
>
>> On Tue, Nov 8, 2016 at 5:28 AM, Malcolm Parsons
>> <malcolm.parsons at gmail.com> wrote:
>> > On 7 November 2016 at 21:11, Aaron Ballman via cfe-dev
>> > <cfe-dev at lists.llvm.org> wrote:
>> >> ifStmt( allOf( hasDescendant(ifStmt()), hasElse(anything()),
>> >> unless(hasAncestor(ifStmt())) ) )
>> >>
>> >> I think that this does not match the top-level if statement because
>> >> hasDescendant(ifStmt()) will not be satisfied -- the top-level if
>> >> statement has no sub statements that are also an if statement.
>> >
>> > hasDescendant != hasChild.
>> >
>> > It's the hasAncestor that is behaving strangely:
>> >
>> > clang-query> match ifStmt(hasDescendant(ifStmt()),
>> > hasAncestor(ifStmt()))
>> >
>> > Match #1:
>> >
>> > ifstmt.c:5:3: note: "root" binds here
>> >   if (a == b) {
>> >   ^~~~~~~~~~~~~
>> > 1 match.
>> > clang-query> match ifStmt(hasDescendant(ifStmt()),
>> > hasAncestor(ifStmt().bind("ancestor")))
>> > 0 matches.
>>
>> Okay, that is really strange. Adding a .bind() should not alter the
>> matches, as far as I'm aware. Manuel or Samuel, can you shed some
>> light on this? I think it's a bug.
>>
>> ~Aaron
>>
>> >
>> > --
>> > Malcolm Parsons
>>
>


-- 
Farzad Sadeghi



More information about the cfe-dev mailing list