Author: mgehre Date: Thu Jul 14 15:00:48 2016 New Revision: 275461 URL: http://llvm.org/viewvc/llvm-project?rev=275461&view=rev Log: cppcoreguidelines-pro-bounds-constant-array-index: crash for value dependent index in c++03 mode
Summary: When the expression is value dependent, isIntegerConstantExpr() crashes in C++03 mode with ../tools/clang/lib/AST/ExprConstant.cpp:9330: (anonymous namespace)::ICEDiag CheckICE(const clang::Expr *, const clang::ASTContext &): Assertion `!E->isValueDependent() && "Should not see value dependent exprs!"' failed. In C++11 mode, that assert does not trigger. This commit works around this in the check. We don't check value-dependent indices and instead check their specialization. Reviewers: alexfh, aaron.ballman Subscribers: nemanjai, cfe-commits Differential Revision: http://reviews.llvm.org/D22190 Added: clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-constant-array-index-c++03.cpp Modified: clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp Modified: clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp?rev=275461&r1=275460&r2=275461&view=diff ============================================================================== --- clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp (original) +++ clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp Thu Jul 14 15:00:48 2016 @@ -65,6 +65,10 @@ void ProBoundsConstantArrayIndexCheck::c const MatchFinder::MatchResult &Result) { const auto *Matched = Result.Nodes.getNodeAs<Expr>("expr"); const auto *IndexExpr = Result.Nodes.getNodeAs<Expr>("index"); + + if (IndexExpr->isValueDependent()) + return; // We check in the specialization. + llvm::APSInt Index; if (!IndexExpr->isIntegerConstantExpr(Index, *Result.Context, nullptr, /*isEvaluated=*/true)) { Added: clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-constant-array-index-c++03.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-constant-array-index-c%2B%2B03.cpp?rev=275461&view=auto ============================================================================== --- clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-constant-array-index-c++03.cpp (added) +++ clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-constant-array-index-c++03.cpp Thu Jul 14 15:00:48 2016 @@ -0,0 +1,11 @@ +// RUN: clang-tidy %s -checks=-*,cppcoreguidelines-pro-bounds-constant-array-index -- -std=c++03 | count 0 + +// Note: this test expects no diagnostics, but FileCheck cannot handle that, +// hence the use of | count 0. +template <int index> struct B { + int get() { + // The next line used to crash the check (in C++03 mode only). + return x[index]; + } + int x[3]; +}; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits