r186385 - Limit number of bits in size representation so that bit size fit 64 bits.

Serge Pavlov sepavloff at gmail.com
Tue Jul 16 00:14:18 PDT 2013


Author: sepavloff
Date: Tue Jul 16 02:14:18 2013
New Revision: 186385

URL: http://llvm.org/viewvc/llvm-project?rev=186385&view=rev
Log:
Limit number of bits in size representation so that bit size fit 64 bits.
This fixes PR8256 and some others.

Modified:
    cfe/trunk/lib/AST/Type.cpp
    cfe/trunk/test/Sema/array-size-64.c
    cfe/trunk/test/Sema/offsetof-64.c

Modified: cfe/trunk/lib/AST/Type.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Type.cpp?rev=186385&r1=186384&r2=186385&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Type.cpp (original)
+++ cfe/trunk/lib/AST/Type.cpp Tue Jul 16 02:14:18 2013
@@ -111,11 +111,12 @@ unsigned ConstantArrayType::getNumAddres
 unsigned ConstantArrayType::getMaxSizeBits(ASTContext &Context) {
   unsigned Bits = Context.getTypeSize(Context.getSizeType());
   
-  // GCC appears to only allow 63 bits worth of address space when compiling
-  // for 64-bit, so we do the same.
-  if (Bits == 64)
-    --Bits;
-  
+  // Limit the number of bits in size_t so that maximal bit size fits 64 bit
+  // integer (see PR8256).  We can do this as currently there is no hardware
+  // that supports full 64-bit virtual space.
+  if (Bits > 61)
+    Bits = 61;
+
   return Bits;
 }
 

Modified: cfe/trunk/test/Sema/array-size-64.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/array-size-64.c?rev=186385&r1=186384&r2=186385&view=diff
==============================================================================
--- cfe/trunk/test/Sema/array-size-64.c (original)
+++ cfe/trunk/test/Sema/array-size-64.c Tue Jul 16 02:14:18 2013
@@ -2,6 +2,11 @@
 
 void f() {
   int a[2147483647U][2147483647U]; // expected-error{{array is too large}}
-  int b[1073741825U - 1U][2147483647U];
-  int c[18446744073709551615U/sizeof(int)/2];
+  int b[1073741825U - 1U][2147483647U]; // expected-error{{array is too large}}
 }
+
+void pr8256 () {
+  typedef char a[1LL<<61];  // expected-error {{array is too large}}
+  typedef char b[(long long)sizeof(a)-1];
+}
+

Modified: cfe/trunk/test/Sema/offsetof-64.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/offsetof-64.c?rev=186385&r1=186384&r2=186385&view=diff
==============================================================================
--- cfe/trunk/test/Sema/offsetof-64.c (original)
+++ cfe/trunk/test/Sema/offsetof-64.c Tue Jul 16 02:14:18 2013
@@ -2,7 +2,7 @@
 
 // PR15216
 // Don't crash when taking computing the offset of structs with large arrays.
-const unsigned long Size = (1l << 62);
+const unsigned long Size = (1l << 60);
 
 struct Chunk1 {
   char padding[Size];





More information about the cfe-commits mailing list