[cfe-commits] r139990 - in /cfe/trunk: lib/Sema/SemaChecking.cpp test/SemaCXX/array-bounds.cpp

Nico Weber nicolasweber at gmx.de
Sat Sep 17 15:59:41 PDT 2011


Author: nico
Date: Sat Sep 17 17:59:41 2011
New Revision: 139990

URL: http://llvm.org/viewvc/llvm-project?rev=139990&view=rev
Log:
Let -Warray-bounds handle casted array types without false positives.

Fixes PR10771.


Modified:
    cfe/trunk/lib/Sema/SemaChecking.cpp
    cfe/trunk/test/SemaCXX/array-bounds.cpp

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=139990&r1=139989&r2=139990&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Sat Sep 17 17:59:41 2011
@@ -3709,7 +3709,7 @@
       return;
 
     const Type* BaseType = getElementType(BaseExpr);
-    if (!isSubscript && BaseType != EffectiveType) {
+    if (BaseType != EffectiveType) {
       // Make sure we're comparing apples to apples when comparing index to size
       uint64_t ptrarith_typesize = Context.getTypeSize(EffectiveType);
       uint64_t array_typesize = Context.getTypeSize(BaseType);

Modified: cfe/trunk/test/SemaCXX/array-bounds.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/array-bounds.cpp?rev=139990&r1=139989&r2=139990&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/array-bounds.cpp (original)
+++ cfe/trunk/test/SemaCXX/array-bounds.cpp Sat Sep 17 17:59:41 2011
@@ -214,3 +214,15 @@
   else
     return foo[5]; // expected-warning {{array index of '5' indexes past the end of an array (that contains 5 elements)}}
 }
+
+void test_pr10771() {
+    double foo[4096];  // expected-note {{array 'foo' declared here}}
+
+    ((char*)foo)[sizeof(foo) - 1] = '\0';  // no-warning
+    *(((char*)foo) + sizeof(foo) - 1) = '\0';  // no-warning
+
+    ((char*)foo)[sizeof(foo)] = '\0';  // expected-warning {{array index of '32768' indexes past the end of an array (that contains 32768 elements)}}
+
+    // TODO: This should probably warn, too.
+    *(((char*)foo) + sizeof(foo)) = '\0';  // no-warning
+}





More information about the cfe-commits mailing list