Author: Zinovy Nis
Date: 2020-06-05T18:43:57+03:00
New Revision: c063b4a72bb39d9ae4bd13851873ddcbc16f6804

URL: 
https://github.com/llvm/llvm-project/commit/c063b4a72bb39d9ae4bd13851873ddcbc16f6804
DIFF: 
https://github.com/llvm/llvm-project/commit/c063b4a72bb39d9ae4bd13851873ddcbc16f6804.diff

LOG: Fix crash on misc-redundant-expression

Differential Revision: https://reviews.llvm.org/D80896

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
index edb765b287f9..aef513a527b5 100644
--- a/clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
@@ -72,8 +72,8 @@ static bool areEquivalentExpr(const Expr *Left, const Expr 
*Right) {
   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),
-                           dyn_cast<Expr>(*RightIter)))
+    if (!areEquivalentExpr(dyn_cast_or_null<Expr>(*LeftIter),
+                           dyn_cast_or_null<Expr>(*RightIter)))
       return false;
     ++LeftIter;
     ++RightIter;
@@ -117,6 +117,9 @@ static bool areEquivalentExpr(const Expr *Left, const Expr 
*Right) {
   case Stmt::MemberExprClass:
     return cast<MemberExpr>(Left)->getMemberDecl() ==
            cast<MemberExpr>(Right)->getMemberDecl();
+  case Stmt::CXXFoldExprClass:
+    return cast<CXXFoldExpr>(Left)->getOperator() ==
+           cast<CXXFoldExpr>(Right)->getOperator();
   case Stmt::CXXFunctionalCastExprClass:
   case Stmt::CStyleCastExprClass:
     return cast<ExplicitCastExpr>(Left)->getTypeAsWritten() ==

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/misc-redundant-expression.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/misc-redundant-expression.cpp
index 4a4304be9bf4..c47ef7d36ff5 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/misc-redundant-expression.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/misc-redundant-expression.cpp
@@ -793,4 +793,10 @@ struct Bar {
     return foo < GetFoo() && foo < maybe_foo;
   }
 };
-}
+
+template <class... Values>
+struct Bar2 {
+  static_assert((... && (sizeof(Values) > 0)) == (... && (sizeof(Values) > 
0)));
+  // CHECK-MESSAGES: :[[@LINE-1]]:47: warning: both sides of operator are 
equivalent [misc-redundant-expression]
+};
+} // namespace no_crash


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to