]> granicus.if.org Git - clang/commitdiff
fix PR10384: C++ allows external arrays of incomplete type as well.
authorChris Lattner <sabre@nondot.org>
Fri, 22 Jul 2011 06:27:26 +0000 (06:27 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 22 Jul 2011 06:27:26 +0000 (06:27 +0000)
Many thanks to Eli for reducing this great testcase.

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

lib/CodeGen/CodeGenTypes.cpp
test/CodeGenCXX/incomplete-types.cpp

index ee629ec9b0de65ddd410fdefb8a0f29d53bb605d..87b3da50005b35c7737bb896b0ef8a9b848494d6 100644 (file)
@@ -419,6 +419,14 @@ llvm::Type *CodeGenTypes::ConvertType(QualType T) {
   case Type::ConstantArray: {
     const ConstantArrayType *A = cast<ConstantArrayType>(Ty);
     llvm::Type *EltTy = ConvertTypeForMem(A->getElementType());
+    
+    // Lower arrays of undefined struct type to arrays of i8 just to have a 
+    // concrete type.
+    if (!EltTy->isSized()) {
+      SkippedLayout = true;
+      EltTy = llvm::Type::getInt8Ty(getLLVMContext());
+    }
+
     ResultType = llvm::ArrayType::get(EltTy, A->getSize().getZExtValue());
     break;
   }
index 4f37eeb97549019f18ddca663e20bce301a3cb36..1d4f430e5cb5c58a243bb4bc97110b7d5f6ca2df 100644 (file)
@@ -35,3 +35,9 @@ namespace PR10395 {
   extern T x[];
   T* f() { return x; }
 }
+
+namespace PR10384 {
+  struct X;
+  extern X x[1];
+  X* f() { return x; }
+}