This is an archive of the discontinued LLVM Phabricator instance.

[ASTMatchers] Matchers that take enumerations args provide hints with invalid arguments
ClosedPublic

Authored by njames93 on Apr 5 2020, 7:34 AM.

Details

Summary

This adds support for giving hints when using dynamic matchers with enum args. Take this query, I couldn't figure out why the matcher wasn't working:
(Turns out it needed to be "IntegralToBoolean", but thats another bug itself)

clang-query> match implicitCastExpr(hasCastKind("CK_IntegralToBoolean"))
1:1: Error parsing argument 1 for matcher implicitCastExpr.
1:18: Error building matcher hasCastKind.
1:30: Incorrect type for arg 1. (Expected = string) != (Actual = String)

With this patch the new behaviour looks like this:

clang-query> match implicitCastExpr(hasCastKind("CK_IntegralToBoolean"))
1:1: Error parsing argument 1 for matcher implicitCastExpr.
1:18: Error building matcher hasCastKind.
1:30: Unknown value 'CK_IntegralToBoolean' for arg 1; did you mean 'IntegralToBoolean'

There are no test cases for this yet as there simply isn't any infrastructure for testing errors reported when parsing args that I can see.

Diff Detail

Event Timeline

njames93 created this revision.Apr 5 2020, 7:34 AM
Herald added a project: Restricted Project. · View Herald Transcript
njames93 edited the summary of this revision. (Show Details)Apr 5 2020, 7:39 AM
njames93 updated this revision to Diff 255258.Apr 6 2020, 2:17 AM
  • Remove format artefacts
aaron.ballman added a subscriber: aaron.ballman.

Thank you for working on this, I think it's very useful functionality! I'd appreciate seeing some unit test coverage for these changes.

clang/lib/ASTMatchers/Dynamic/CMakeLists.txt
20

We usually try to keep these lists in alphabetical order. Would you mind hoisting this up a bit (feel free to change VariantValue.cpp as a driveby if you want, or just leave it there)?

clang/lib/ASTMatchers/Dynamic/Marshallers.cpp
11

Elide braces, and please use ~0U instead of -1u.

17–18

Is this case possible to hit? I would imagine that if the search time matches anything in the allowed list, we would have not needed to call getBestGuess() in the first place?

njames93 updated this revision to Diff 255387.Apr 6 2020, 9:54 AM
njames93 marked 4 inline comments as done.
  • Added test cases and addressed nits.
njames93 added inline comments.Apr 6 2020, 9:59 AM
clang/lib/ASTMatchers/Dynamic/Marshallers.cpp
17–18

This one shouldn't be, I put an assert in for sanity though. The one below with the prefix can be hit though.

aaron.ballman accepted this revision.Apr 6 2020, 10:52 AM

LGTM, thank you!

This revision is now accepted and ready to land.Apr 6 2020, 10:52 AM
This revision was automatically updated to reflect the committed changes.