diff options
author | Chris Lattner <sabre@nondot.org> | 2011-07-12 06:52:18 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2011-07-12 06:52:18 +0000 |
commit | 3a2b657088de9413714a51bff153a59565adb3ef (patch) | |
tree | cb71c19b933c4b08606c3d721695e509c3caab26 /lib/CodeGen/CodeGenTypes.cpp | |
parent | 811bf3669f4d82c57fe3cd3c49050fdbc95d0aff (diff) |
Fix a problem Eli ran into where we now reject incomplete arrays of
uncompleted struct types. We now do what llvm-gcc does and compile
them into [i8 x 0]. If the type is later completed, we make sure that
it is appropriately cast.
We compile the terrible example to something like this now:
%struct.A = type { i32, i32, i32 }
@g = external global [0 x i8]
define void @_Z1fv() nounwind {
entry:
call void @_Z3fooP1A(%struct.A* bitcast ([0 x i8]* @g to %struct.A*))
ret void
}
declare void @_Z3fooP1A(%struct.A*)
define %struct.A* @_Z2f2v() nounwind {
entry:
ret %struct.A* getelementptr inbounds ([0 x %struct.A]* bitcast ([0 x i8]* @g to [0 x %struct.A]*), i32 0, i64 1)
}
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@134972 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CodeGenTypes.cpp')
-rw-r--r-- | lib/CodeGen/CodeGenTypes.cpp | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/lib/CodeGen/CodeGenTypes.cpp b/lib/CodeGen/CodeGenTypes.cpp index 64348ea7d1..8efe9e1eea 100644 --- a/lib/CodeGen/CodeGenTypes.cpp +++ b/lib/CodeGen/CodeGenTypes.cpp @@ -92,7 +92,6 @@ llvm::Type *CodeGenTypes::ConvertTypeForMem(QualType T){ // Otherwise, return an integer of the target-specified size. return llvm::IntegerType::get(getLLVMContext(), (unsigned)Context.getTypeSize(T)); - } /// isFuncTypeArgumentConvertible - Return true if the specified type in a @@ -318,8 +317,14 @@ llvm::Type *CodeGenTypes::ConvertType(QualType T) { const IncompleteArrayType *A = cast<IncompleteArrayType>(Ty); assert(A->getIndexTypeCVRQualifiers() == 0 && "FIXME: We only handle trivial array types so far!"); - // int X[] -> [0 x int] - ResultType = llvm::ArrayType::get(ConvertTypeForMem(A->getElementType()),0); + // int X[] -> [0 x int], unless the element type is not sized. If it is + // unsized (e.g. an incomplete struct) just use [0 x i8]. + ResultType = ConvertTypeForMem(A->getElementType()); + if (!ResultType->isSized()) { + SkippedLayout = true; + ResultType = llvm::Type::getInt8Ty(getLLVMContext()); + } + ResultType = llvm::ArrayType::get(ResultType, 0); break; } case Type::ConstantArray: { |