[PATCH] D80896: [clang-tidy][misc-redundant-expression] Fix crash on CXXFoldExpr

Zinovy Nis via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun May 31 12:14:16 PDT 2020


zinovy.nis created this revision.
zinovy.nis added a reviewer: etienneb.
Herald added subscribers: cfe-commits, xazax.hun.
Herald added a project: clang.

Fix for a crash from https://bugs.llvm.org/show_bug.cgi?id=44256

Bug: https://bugs.llvm.org/show_bug.cgi?id=44256


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D80896

Files:
  clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc-redundant-expression.cpp


Index: clang-tools-extra/test/clang-tidy/checkers/misc-redundant-expression.cpp
===================================================================
--- clang-tools-extra/test/clang-tidy/checkers/misc-redundant-expression.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/misc-redundant-expression.cpp
@@ -793,4 +793,10 @@
     return foo < GetFoo() && foo < maybe_foo;
   }
 };
+
+template <class... Values>
+struct Bar2 {
+  static_assert(
+      (... && (sizeof(Values) > 0)) || (... && (sizeof(Values) < 0)));
+};
 }
Index: clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
+++ clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
@@ -72,7 +72,7 @@
   Expr::const_child_iterator LeftIter = Left->child_begin();
   Expr::const_child_iterator RightIter = Right->child_begin();
   while (LeftIter != Left->child_end() && RightIter != Right->child_end()) {
-    if (!areEquivalentExpr(dyn_cast<Expr>(*LeftIter),
+    if (*LeftIter && *RightIter && !areEquivalentExpr(dyn_cast<Expr>(*LeftIter),
                            dyn_cast<Expr>(*RightIter)))
       return false;
     ++LeftIter;
@@ -117,6 +117,13 @@
   case Stmt::MemberExprClass:
     return cast<MemberExpr>(Left)->getMemberDecl() ==
            cast<MemberExpr>(Right)->getMemberDecl();
+  case Stmt::CXXFoldExprClass: {
+    const auto LeftLHS = cast<CXXFoldExpr>(Left)->getLHS();
+    const auto RightLHS = cast<CXXFoldExpr>(Right)->getLHS();
+    const auto LeftRHS = cast<CXXFoldExpr>(Left)->getRHS();
+    const auto RightRHS = cast<CXXFoldExpr>(Right)->getRHS();
+    return areEquivalentExpr(LeftLHS, RightLHS) && areEquivalentExpr(LeftRHS, RightRHS);
+  }
   case Stmt::CXXFunctionalCastExprClass:
   case Stmt::CStyleCastExprClass:
     return cast<ExplicitCastExpr>(Left)->getTypeAsWritten() ==


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D80896.267516.patch
Type: text/x-patch
Size: 1926 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200531/f12ace39/attachment.bin>


More information about the cfe-commits mailing list