This is an archive of the discontinued LLVM Phabricator instance.

[ASTMatchers] Fix matching after generic top-level matcher
ClosedPublic

Authored by steveire on Jan 30 2021, 5:45 AM.

Details

Summary

With a matcher like

expr(anyOf(integerLiteral(equals(42)), unless(expr())))

and code such as

struct B {
  B(int);
};

B func1() { return 42; }

the top-level expr() would match each of the nodes which are not spelled
in the source and then ignore-traverse to match the integerLiteral node.
This would result in multiple results reported for the integerLiteral.

Fix that by only running matching logic on nodes which are not skipped
with the top-level matcher.

Diff Detail

Event Timeline

steveire requested review of this revision.Jan 30 2021, 5:45 AM
steveire created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptJan 30 2021, 5:45 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript

I'm a bit confused -- I only get one match when I try out your example: https://godbolt.org/z/xn9efY Are there other changes in-flight that necessitate this, or is something else going on?

I'm a bit confused -- I only get one match when I try out your example: https://godbolt.org/z/xn9efY Are there other changes in-flight that necessitate this, or is something else going on?

Yes, only IgnoreUnlessSpelledInSource mode is affected: https://godbolt.org/z/ffareK

aaron.ballman accepted this revision.Feb 2 2021, 5:25 AM

I'm a bit confused -- I only get one match when I try out your example: https://godbolt.org/z/xn9efY Are there other changes in-flight that necessitate this, or is something else going on?

Yes, only IgnoreUnlessSpelledInSource mode is affected: https://godbolt.org/z/ffareK

Ahhh, of course, thank you! LGTM

This revision is now accepted and ready to land.Feb 2 2021, 5:25 AM
This revision was landed with ongoing or failed builds.Feb 2 2021, 5:32 AM
This revision was automatically updated to reflect the committed changes.