[PATCH] D66273: [Tooling] Add a hack to work around issues with matcher binding in r368681.

David L. Jones via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 14 21:04:31 PDT 2019

dlj created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The change in r368681 contains a (probably unintentional) behavioral change for
rewrite rules with a single matcher. Previously, the single matcher would not
need to be bound (`joinCaseMatchers` returned it directly), even though a final
DynTypeMatcher was created and bound by `buildMatcher`. With the new change, a
single matcher will be bound, in addition to the final binding (which is now in
`buildMatchers`, but happens roughly at the same point in the overall flow).

This patch simply duplicates the "final matcher" trick: it creates an extra
DynTypedMatcher for each rewrite rule case matcher, and unconditionally makes it
bindable. This is probably not the right long-term fix, but it does allow
existing code to continue to work with this interface.

  rG LLVM Github Monorepo



Index: clang/lib/Tooling/Refactoring/Transformer.cpp
--- clang/lib/Tooling/Refactoring/Transformer.cpp
+++ clang/lib/Tooling/Refactoring/Transformer.cpp
@@ -98,8 +98,10 @@
   for (const auto &Case : Cases) {
     std::string Tag = (TagBase + Twine(Case.first)).str();
-    auto M = Case.second.Matcher.tryBind(Tag);
-    assert(M && "RewriteRule matchers should be bindable.");
+    // HACK: Many matchers are not bindable, so ensure that tryBind will work.
+    DynTypedMatcher BoundMatcher(Case.second.Matcher);
+    BoundMatcher.setAllowBind(true);
+    auto M = BoundMatcher.tryBind(Tag);
   return Matchers;

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D66273.215316.patch
Type: text/x-patch
Size: 761 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190815/07e3726c/attachment.bin>

More information about the cfe-commits mailing list