]> granicus.if.org Git - clang/commitdiff
Limit number of bits in size representation so that bit size fit 64 bits.
authorSerge Pavlov <sepavloff@gmail.com>
Tue, 16 Jul 2013 07:14:18 +0000 (07:14 +0000)
committerSerge Pavlov <sepavloff@gmail.com>
Tue, 16 Jul 2013 07:14:18 +0000 (07:14 +0000)
This fixes PR8256 and some others.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@186385 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/Type.cpp
test/Sema/array-size-64.c
test/Sema/offsetof-64.c

index af4ea096721a45c1f58e9f5ce5403f41ab971eb3..4068b2b8988a6e5f72cee6e1415245ebd1027493 100644 (file)
@@ -111,11 +111,12 @@ unsigned ConstantArrayType::getNumAddressingBits(ASTContext &Context,
 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;
 }
 
index f22e8e77d2151eb1f446151cd99ddfaa191dfe04..0e094bfa6bd72792b1b47ec84025cb5e50a6b6d7 100644 (file)
@@ -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];
+}
+
index fb3d6e98d1c7b98845137d4a0076ad3b5eb74cbc..4a80dee2fc2fbe8901eae846695c629ba972a1d3 100644 (file)
@@ -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];