]> granicus.if.org Git - clang/commitdiff
Fix bogus -Warray-bounds warning involving 'array[true]' reported in PR 9296.
authorTed Kremenek <kremenek@apple.com>
Wed, 23 Feb 2011 23:06:04 +0000 (23:06 +0000)
committerTed Kremenek <kremenek@apple.com>
Wed, 23 Feb 2011 23:06:04 +0000 (23:06 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@126341 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaChecking.cpp
test/SemaCXX/array-bounds.cpp

index edee8af72bb54f0a83c3d7a8b26b93016734ba58..5c2356f54db98e62e52715fb04381d5391aabc6c 100644 (file)
@@ -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;
index e82ce6013894b95bd940cc25861403a8373fc9cf..80646c719078ec7650c8be9285194596e73aa0d1 100644 (file)
@@ -115,3 +115,8 @@ void test_pr9284() {
     pr9284b<false>(); // expected-note{{in instantiation of function template specialization 'pr9284b<false>' requested here}}
 }
 
+int test_pr9296() {
+    int array[2];
+    return array[true]; // no-warning
+}
+