=?utf-8?q?Balázs_Kéri?= <[email protected]>,
=?utf-8?q?Balázs_Kéri?= <[email protected]>
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/[email protected]>


================
@@ -0,0 +1,148 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "AssignmentInSelectionStatementCheck.h"
+#include "clang/AST/IgnoreExpr.h"
+#include "clang/AST/StmtVisitor.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "llvm/ADT/TypeSwitch.h"
+
+using namespace clang;
+using namespace clang::ast_matchers;
+
+namespace {
+
+class ConditionValueCanPropagateFrom
+    : public ConstStmtVisitor<ConditionValueCanPropagateFrom, void> {
+public:
+  llvm::SmallVector<const Expr *, 2> ExprToProcess;
+
+  void VisitBinaryOperator(const BinaryOperator *BO) {
+    if (BO->isCommaOp())
+      ExprToProcess.push_back(BO->getRHS()->IgnoreParenImpCasts());
+  }
+  void VisitConditionalOperator(const ConditionalOperator *CO) {
+    ExprToProcess.push_back(CO->getFalseExpr()->IgnoreParenImpCasts());
+    ExprToProcess.push_back(CO->getTrueExpr()->IgnoreParenImpCasts());
+  }
+};
+
+AST_MATCHER_P(Expr, conditionValueCanPropagateFrom,
+              ast_matchers::internal::Matcher<Expr>, InnerMatcher) {
+  bool Found = false;
+  ConditionValueCanPropagateFrom Visitor;
+  Visitor.Visit(&Node); // Do not match Node itself.
+  while (!Visitor.ExprToProcess.empty()) {
+    const Expr *E = Visitor.ExprToProcess.pop_back_val();
+    ast_matchers::internal::BoundNodesTreeBuilder Result;
+    if (InnerMatcher.matches(*E, Finder, &Result)) {
+      Found = true;
+      Builder->addMatch(Result);
+    }
+    Visitor.Visit(E);
+  }
+  return Found;
+}
+
+// Ignore implicit casts (including C++ conversion member calls) but not 
parens.
+AST_MATCHER_P(Expr, ignoringImplicitAsWritten,
+              ast_matchers::internal::Matcher<Expr>, InnerMatcher) {
+  auto IgnoreImplicitMemberCallSingleStep = [](Expr *E) {
+    if (auto *C = dyn_cast<CXXMemberCallExpr>(E)) {
+      Expr *ExprNode = C->getImplicitObjectArgument();
+      if (ExprNode->getSourceRange() == E->getSourceRange())
+        return ExprNode;
+      if (auto *PE = dyn_cast<ParenExpr>(ExprNode)) {
+        if (PE->getSourceRange() == C->getSourceRange())
+          return cast<Expr>(PE);
----------------
vbvictor wrote:

Do we need `cast`? `ParenExpr` already an `Expr`

https://github.com/llvm/llvm-project/pull/180219
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to