Skip to content

Commit

Permalink
fix PR10384: C++ allows external arrays of incomplete type as well.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
lattner committed Jul 22, 2011
1 parent 018ec41 commit 01c5d1d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/CodeGen/CodeGenTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
6 changes: 6 additions & 0 deletions test/CodeGenCXX/incomplete-types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}

0 comments on commit 01c5d1d

Please sign in to comment.