Fix crash on misc-redundant-expression

Differential Revision: https://reviews.llvm.org/D80896
This commit is contained in:
Zinovy Nis 2020-05-31 21:53:13 +03:00 committed by Zinovy Nis
parent fe82d3a3ae
commit c063b4a72b
2 changed files with 12 additions and 3 deletions

View File

@ -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() ==

View File

@ -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