[clang] [clang][ASTMatcher] Fix execution order of hasOperands submatchers (PR #104148)
Nicolas van Kempen via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 14 11:54:43 PDT 2024
https://github.com/nicovank updated https://github.com/llvm/llvm-project/pull/104148
>From 168f812b5817ea2a9a80e0a6b52b2005e57d327c Mon Sep 17 00:00:00 2001
From: Nicolas van Kempen <nvankemp at gmail.com>
Date: Wed, 14 Aug 2024 14:54:20 -0400
Subject: [PATCH] [clang][ASTMatcher] Fix execution order of hasOperands
submatchers
The `hasOperands` matcher does not always execute matchers in the order they are
written. This can cause issue in code using bindings when one operand matcher is
relying on a binding set by the other. With this change, the first matcher
present in the code is always executed first and any binding it sets are
available to the second matcher.
---
clang/include/clang/ASTMatchers/ASTMatchers.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h b/clang/include/clang/ASTMatchers/ASTMatchers.h
index ca44c3ee085654..f1c72efc238784 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -6027,7 +6027,7 @@ AST_POLYMORPHIC_MATCHER_P2(
internal::Matcher<Expr>, Matcher1, internal::Matcher<Expr>, Matcher2) {
return internal::VariadicDynCastAllOfMatcher<Stmt, NodeType>()(
anyOf(allOf(hasLHS(Matcher1), hasRHS(Matcher2)),
- allOf(hasLHS(Matcher2), hasRHS(Matcher1))))
+ allOf(hasRHS(Matcher1), hasLHS(Matcher2))))
.matches(Node, Finder, Builder);
}
More information about the cfe-commits
mailing list