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

Ted Kremenek kremenek at apple.com
Thu Feb 17 18:27:00 PST 2011


Author: kremenek
Date: Thu Feb 17 20:27:00 2011
New Revision: 125821

URL: http://llvm.org/viewvc/llvm-project?rev=125821&view=rev
Log:
Fix assertion failure on -Warray-bounds for 32-bit builds of Clang.

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=125821&r1=125820&r2=125821&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Thu Feb 17 20:27:00 2011
@@ -3109,11 +3109,14 @@
     return;
 
   if (!index.isNegative()) {
-    const llvm::APInt &size = ArrayTy->getSize();
+    llvm::APInt size = ArrayTy->getSize();
     if (!size.isStrictlyPositive())
       return;
     if (size.getBitWidth() > index.getBitWidth())
       index = index.sext(size.getBitWidth());
+    else if (size.getBitWidth() < index.getBitWidth())
+      size = size.sext(index.getBitWidth());
+
     if (index.slt(size))
       return;
 

Modified: cfe/trunk/test/SemaCXX/array-bounds.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/array-bounds.cpp?rev=125821&r1=125820&r2=125821&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/array-bounds.cpp (original)
+++ cfe/trunk/test/SemaCXX/array-bounds.cpp Thu Feb 17 20:27:00 2011
@@ -85,3 +85,9 @@
          ARR_IN_MACRO(1, arr, SIZE); // expected-warning{{array index of '10' indexes past the end of an array (that contains 10 elements)}}
 }
 
+// This exhibited an assertion failure for a 32-bit build of Clang.
+int test_pr9240() {
+  short array[100]; // expected-note {{array 'array' declared here}}
+  return array[(unsigned long long) 100]; // expected-warning {{array index of '100' indexes past the end of an array (that contains 100 elements)}}
+}
+





More information about the cfe-commits mailing list