[clang] [clang][transformer] Allow usage of applyFirst with rewriteDescendants (PR #117658)

Yitzhak Mandelbaum via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 30 13:37:06 PST 2024


ymand wrote:

> Yes, indeed the original match happens in separate context, but all contexts share one `NodesMap`, which values are overriden with a consecutive match ('clash').

I see -- I'd missed the reuse of the MatchResult. Now that I understand the problem, I don't think that you're suggestion will fix it.  The problem is that the IDs of the matchers are unique between different matchers, but not necessarily unique within a rule, because you can trivially reuse a matcher twice within the rule. So, we need a different source of uniqueness.

I don't have a quick fix offhand -- I think we'd probably want to package the ID with the rule case and then use a unique-ID generator (e.g. a global int variable) when we create the cases. But, in the meantime, if you want to unblock your progress, you could combine the position-based ID with the matcher-based ID, which would significantly decrease the likelihood of conflict. But, if you do that, please include a simple test that demonstrates the problem.

thanks!

https://github.com/llvm/llvm-project/pull/117658


More information about the cfe-commits mailing list