diff --git a/clang/lib/CodeGen/CodeGenTypes.cpp b/clang/lib/CodeGen/CodeGenTypes.cpp index ee629ec9b0de..87b3da50005b 100644 --- a/clang/lib/CodeGen/CodeGenTypes.cpp +++ b/clang/lib/CodeGen/CodeGenTypes.cpp @@ -419,6 +419,14 @@ llvm::Type *CodeGenTypes::ConvertType(QualType T) { case Type::ConstantArray: { const ConstantArrayType *A = cast(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; } diff --git a/clang/test/CodeGenCXX/incomplete-types.cpp b/clang/test/CodeGenCXX/incomplete-types.cpp index 4f37eeb97549..1d4f430e5cb5 100644 --- a/clang/test/CodeGenCXX/incomplete-types.cpp +++ b/clang/test/CodeGenCXX/incomplete-types.cpp @@ -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; } +}