diff options
author | Chris Lattner <sabre@nondot.org> | 2010-06-30 19:14:05 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2010-06-30 19:14:05 +0000 |
commit | bcaedaed309ce453a992fdeef4a4c908cc7d9dfb (patch) | |
tree | 62dfcba7c7efee298a560c834ad72d290eff8500 /lib/CodeGen/CodeGenTypes.cpp | |
parent | e81c5619f11e1ececf99ff30d15e5abfb6ea0c28 (diff) |
Reapply:
r107173, "fix PR7519: after thrashing around and remembering how all this stuff"
r107216, "fix PR7523, which was caused by the ABI code calling ConvertType instead"
This includes a fix to make ConvertTypeForMem handle the "recursive" case, and call
it as such when lowering function types which have an indirect result.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@107310 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CodeGenTypes.cpp')
-rw-r--r-- | lib/CodeGen/CodeGenTypes.cpp | 59 |
1 files changed, 34 insertions, 25 deletions
diff --git a/lib/CodeGen/CodeGenTypes.cpp b/lib/CodeGen/CodeGenTypes.cpp index cf23c07394..7876e5aefc 100644 --- a/lib/CodeGen/CodeGenTypes.cpp +++ b/lib/CodeGen/CodeGenTypes.cpp @@ -43,10 +43,15 @@ CodeGenTypes::~CodeGenTypes() { } /// ConvertType - Convert the specified type to its LLVM form. -const llvm::Type *CodeGenTypes::ConvertType(QualType T) { - llvm::PATypeHolder Result = ConvertTypeRecursive(T); +const llvm::Type *CodeGenTypes::ConvertType(QualType T, bool IsRecursive) { + const llvm::Type *RawResult = ConvertTypeRecursive(T); + + if (IsRecursive || PointersToResolve.empty()) + return RawResult; - // Any pointers that were converted defered evaluation of their pointee type, + llvm::PATypeHolder Result = RawResult; + + // Any pointers that were converted deferred evaluation of their pointee type, // creating an opaque type instead. This is in order to avoid problems with // circular types. Loop through all these defered pointees, if any, and // resolve them now. @@ -80,21 +85,12 @@ const llvm::Type *CodeGenTypes::ConvertTypeRecursive(QualType T) { return ResultType; } -const llvm::Type *CodeGenTypes::ConvertTypeForMemRecursive(QualType T) { - const llvm::Type *ResultType = ConvertTypeRecursive(T); - if (ResultType->isIntegerTy(1)) - return llvm::IntegerType::get(getLLVMContext(), - (unsigned)Context.getTypeSize(T)); - // FIXME: Should assert that the llvm type and AST type has the same size. - return ResultType; -} - /// ConvertTypeForMem - Convert type T into a llvm::Type. This differs from /// ConvertType in that it is used to convert to the memory representation for /// a type. For example, the scalar representation for _Bool is i1, but the /// memory representation is usually i8 or i32, depending on the target. -const llvm::Type *CodeGenTypes::ConvertTypeForMem(QualType T) { - const llvm::Type *R = ConvertType(T); +const llvm::Type *CodeGenTypes::ConvertTypeForMem(QualType T, bool IsRecursive){ + const llvm::Type *R = ConvertType(T, IsRecursive); // If this is a non-bool type, don't map it. if (!R->isIntegerTy(1)) @@ -284,7 +280,8 @@ const llvm::Type *CodeGenTypes::ConvertNewType(QualType T) { assert(A.getIndexTypeCVRQualifiers() == 0 && "FIXME: We only handle trivial array types so far!"); // int X[] -> [0 x int] - return llvm::ArrayType::get(ConvertTypeForMemRecursive(A.getElementType()), 0); + return llvm::ArrayType::get(ConvertTypeForMemRecursive(A.getElementType()), + 0); } case Type::ConstantArray: { const ConstantArrayType &A = cast<ConstantArrayType>(Ty); @@ -299,7 +296,11 @@ const llvm::Type *CodeGenTypes::ConvertNewType(QualType T) { } case Type::FunctionNoProto: case Type::FunctionProto: { - // First, check whether we can build the full function type. + // First, check whether we can build the full function type. If the + // function type depends on an incomplete type (e.g. a struct or enum), we + // cannot lower the function type. Instead, turn it into an Opaque pointer + // and have UpdateCompletedType revisit the function type when/if the opaque + // argument type is defined. if (const TagType *TT = VerifyFuncTypeComplete(&Ty)) { // This function's type depends on an incomplete tag type; make sure // we have an opaque type corresponding to the tag type. @@ -309,17 +310,25 @@ const llvm::Type *CodeGenTypes::ConvertNewType(QualType T) { FunctionTypes.insert(std::make_pair(&Ty, ResultType)); return ResultType; } + // The function type can be built; call the appropriate routines to // build it. - if (const FunctionProtoType *FPT = dyn_cast<FunctionProtoType>(&Ty)) - return GetFunctionType(getFunctionInfo( - CanQual<FunctionProtoType>::CreateUnsafe(QualType(FPT,0))), - FPT->isVariadic()); - - const FunctionNoProtoType *FNPT = cast<FunctionNoProtoType>(&Ty); - return GetFunctionType(getFunctionInfo( - CanQual<FunctionNoProtoType>::CreateUnsafe(QualType(FNPT,0))), - true); + const CGFunctionInfo *FI; + bool isVariadic; + if (const FunctionProtoType *FPT = dyn_cast<FunctionProtoType>(&Ty)) { + FI = &getFunctionInfo( + CanQual<FunctionProtoType>::CreateUnsafe(QualType(FPT, 0)), + true /*Recursive*/); + isVariadic = FPT->isVariadic(); + } else { + const FunctionNoProtoType *FNPT = cast<FunctionNoProtoType>(&Ty); + FI = &getFunctionInfo( + CanQual<FunctionNoProtoType>::CreateUnsafe(QualType(FNPT, 0)), + true /*Recursive*/); + isVariadic = true; + } + + return GetFunctionType(*FI, isVariadic, true); } case Type::ObjCObject: |