diff options
author | Dmitri Gribenko <gribozavr@gmail.com> | 2019-06-12 08:40:53 +0000 |
---|---|---|
committer | Dmitri Gribenko <gribozavr@gmail.com> | 2019-06-12 08:40:53 +0000 |
commit | cf7d76835157e28fa5be626031d5cec83f8007b6 (patch) | |
tree | 8301005af2e0effe24e1d882f321278a04a70154 /clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp | |
parent | a94715639619a258a714deeb485d2d7fb9dd1cb9 (diff) | |
download | bcm5719-llvm-cf7d76835157e28fa5be626031d5cec83f8007b6.tar.gz bcm5719-llvm-cf7d76835157e28fa5be626031d5cec83f8007b6.zip |
Fixed a crash in misc-redundant-expression ClangTidy checker
Summary: It was trying to pass a dependent expression into constant evaluator.
Reviewers: ilya-biryukov
Subscribers: cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D63188
llvm-svn: 363133
Diffstat (limited to 'clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp')
-rw-r--r-- | clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp b/clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp index 5167315dea4..3cec1fb935d 100644 --- a/clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp +++ b/clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp @@ -555,10 +555,14 @@ static bool areSidesBinaryConstExpressions(const BinaryOperator *&BinOp, const A if (!LhsBinOp || !RhsBinOp) return false; - if ((LhsBinOp->getLHS()->isIntegerConstantExpr(*AstCtx) || - LhsBinOp->getRHS()->isIntegerConstantExpr(*AstCtx)) && - (RhsBinOp->getLHS()->isIntegerConstantExpr(*AstCtx) || - RhsBinOp->getRHS()->isIntegerConstantExpr(*AstCtx))) + auto IsIntegerConstantExpr = [AstCtx](const Expr *E) { + return !E->isValueDependent() && E->isIntegerConstantExpr(*AstCtx); + }; + + if ((IsIntegerConstantExpr(LhsBinOp->getLHS()) || + IsIntegerConstantExpr(LhsBinOp->getRHS())) && + (IsIntegerConstantExpr(RhsBinOp->getLHS()) || + IsIntegerConstantExpr(RhsBinOp->getRHS()))) return true; return false; } @@ -580,12 +584,14 @@ static bool retrieveConstExprFromBothSides(const BinaryOperator *&BinOp, const auto *BinOpLhs = cast<BinaryOperator>(BinOp->getLHS()); const auto *BinOpRhs = cast<BinaryOperator>(BinOp->getRHS()); - LhsConst = BinOpLhs->getLHS()->isIntegerConstantExpr(*AstCtx) - ? BinOpLhs->getLHS() - : BinOpLhs->getRHS(); - RhsConst = BinOpRhs->getLHS()->isIntegerConstantExpr(*AstCtx) - ? BinOpRhs->getLHS() - : BinOpRhs->getRHS(); + auto IsIntegerConstantExpr = [AstCtx](const Expr *E) { + return !E->isValueDependent() && E->isIntegerConstantExpr(*AstCtx); + }; + + LhsConst = IsIntegerConstantExpr(BinOpLhs->getLHS()) ? BinOpLhs->getLHS() + : BinOpLhs->getRHS(); + RhsConst = IsIntegerConstantExpr(BinOpRhs->getLHS()) ? BinOpRhs->getLHS() + : BinOpRhs->getRHS(); if (!LhsConst || !RhsConst) return false; |