From: Ted Kremenek Date: Wed, 23 Feb 2011 23:06:04 +0000 (+0000) Subject: Fix bogus -Warray-bounds warning involving 'array[true]' reported in PR 9296. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9e060ca641a1f845cecb3371b3a3018d306a5198;p=clang Fix bogus -Warray-bounds warning involving 'array[true]' reported in PR 9296. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@126341 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp index edee8af72b..5c2356f54d 100644 --- a/lib/Sema/SemaChecking.cpp +++ b/lib/Sema/SemaChecking.cpp @@ -3123,7 +3123,7 @@ void Sema::CheckArrayAccess(const clang::ArraySubscriptExpr *E) { if (!IndexExpr->isIntegerConstantExpr(index, Context)) return; - if (!index.isNegative()) { + if (index.isUnsigned() || !index.isNegative()) { llvm::APInt size = ArrayTy->getSize(); if (!size.isStrictlyPositive()) return; diff --git a/test/SemaCXX/array-bounds.cpp b/test/SemaCXX/array-bounds.cpp index e82ce60138..80646c7190 100644 --- a/test/SemaCXX/array-bounds.cpp +++ b/test/SemaCXX/array-bounds.cpp @@ -115,3 +115,8 @@ void test_pr9284() { pr9284b(); // expected-note{{in instantiation of function template specialization 'pr9284b' requested here}} } +int test_pr9296() { + int array[2]; + return array[true]; // no-warning +} +