[PATCH] [Sema] Don't crash on array types with incomplete element type whose bound results in overflow

David Majnemer david.majnemer at gmail.com
Fri Apr 10 01:02:15 PDT 2015


Hi rsmith,

We can't be sure that an array is too large without knowing how large
array elements are.

http://reviews.llvm.org/D8962

Files:
  lib/Sema/SemaDecl.cpp
  test/CXX/dcl.dcl/dcl.spec/dcl.typedef/p2-0x.cpp

Index: lib/Sema/SemaDecl.cpp
===================================================================
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -4862,7 +4862,8 @@
   if (!VLATy)
     return QualType();
   // FIXME: We should probably handle this case
-  if (VLATy->getElementType()->isVariablyModifiedType())
+  if (VLATy->getElementType()->isVariablyModifiedType() ||
+      VLATy->getElementType()->isIncompleteType())
     return QualType();
 
   llvm::APSInt Res;
Index: test/CXX/dcl.dcl/dcl.spec/dcl.typedef/p2-0x.cpp
===================================================================
--- test/CXX/dcl.dcl/dcl.spec/dcl.typedef/p2-0x.cpp
+++ test/CXX/dcl.dcl/dcl.spec/dcl.typedef/p2-0x.cpp
@@ -42,6 +42,9 @@
   using U = int[42]; // ok
   using U = int; // expected-error {{type alias redefinition with different types ('int' vs 'int [42]')}}
 
+  using V = struct A[  // expected-error {{variable length array declaration not allowed at file scope}}
+      (1 << 30) << 2]; // expected-warning {{requires 34 bits to represent}}
+
   void f() {
     int n = 42;
     goto foo; // expected-error {{cannot jump}}

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D8962.23580.patch
Type: text/x-patch
Size: 1124 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150410/16a39168/attachment.bin>


More information about the cfe-commits mailing list