From 376fe5e7800dface235c5382b39d77790d39dfa7 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Tue, 29 Jun 2010 17:56:33 +0000 Subject: [PATCH] fix PR7519: after thrashing around and remembering how all this stuff works, the fix is quite simple: just make sure to call ConvertTypeRecursive when the function type being lowered is in the midst of ConvertType. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@107173 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGCall.cpp | 31 +++++++++++++++++++++--------- lib/CodeGen/CodeGenTypes.cpp | 37 ++++++++++++++++++++++++------------ lib/CodeGen/CodeGenTypes.h | 10 +++++++--- lib/CodeGen/TargetInfo.cpp | 3 +-- test/CodeGen/decl.c | 13 +++++++++++++ 5 files changed, 68 insertions(+), 26 deletions(-) diff --git a/lib/CodeGen/CGCall.cpp b/lib/CodeGen/CGCall.cpp index bfc22d1bc7..cbcd3d1233 100644 --- a/lib/CodeGen/CGCall.cpp +++ b/lib/CodeGen/CGCall.cpp @@ -61,28 +61,31 @@ static CanQualType GetReturnType(QualType RetTy) { } const CGFunctionInfo & -CodeGenTypes::getFunctionInfo(CanQual FTNP) { +CodeGenTypes::getFunctionInfo(CanQual FTNP, + bool IsRecursive) { return getFunctionInfo(FTNP->getResultType().getUnqualifiedType(), llvm::SmallVector(), - FTNP->getExtInfo()); + FTNP->getExtInfo(), IsRecursive); } /// \param Args - contains any initial parameters besides those /// in the formal type static const CGFunctionInfo &getFunctionInfo(CodeGenTypes &CGT, llvm::SmallVectorImpl &ArgTys, - CanQual FTP) { + CanQual FTP, + bool IsRecursive = false) { // FIXME: Kill copy. for (unsigned i = 0, e = FTP->getNumArgs(); i != e; ++i) ArgTys.push_back(FTP->getArgType(i)); CanQualType ResTy = FTP->getResultType().getUnqualifiedType(); - return CGT.getFunctionInfo(ResTy, ArgTys, FTP->getExtInfo()); + return CGT.getFunctionInfo(ResTy, ArgTys, FTP->getExtInfo(), IsRecursive); } const CGFunctionInfo & -CodeGenTypes::getFunctionInfo(CanQual FTP) { +CodeGenTypes::getFunctionInfo(CanQual FTP, + bool IsRecursive) { llvm::SmallVector ArgTys; - return ::getFunctionInfo(*this, ArgTys, FTP); + return ::getFunctionInfo(*this, ArgTys, FTP, IsRecursive); } static CallingConv getCallingConventionForDecl(const Decl *D) { @@ -215,7 +218,8 @@ const CGFunctionInfo &CodeGenTypes::getFunctionInfo(QualType ResTy, const CGFunctionInfo &CodeGenTypes::getFunctionInfo(CanQualType ResTy, const llvm::SmallVectorImpl &ArgTys, - const FunctionType::ExtInfo &Info) { + const FunctionType::ExtInfo &Info, + bool IsRecursive) { #ifndef NDEBUG for (llvm::SmallVectorImpl::const_iterator I = ArgTys.begin(), E = ArgTys.end(); I != E; ++I) @@ -243,8 +247,17 @@ const CGFunctionInfo &CodeGenTypes::getFunctionInfo(CanQualType ResTy, // various situations, pass it in. llvm::SmallVector PreferredArgTypes; for (llvm::SmallVectorImpl::const_iterator - I = ArgTys.begin(), E = ArgTys.end(); I != E; ++I) - PreferredArgTypes.push_back(ConvertType(*I)); + I = ArgTys.begin(), E = ArgTys.end(); I != E; ++I) { + // If this is being called from the guts of the ConvertType loop, make sure + // to call ConvertTypeRecursive so we don't get into issues with cyclic + // pointer type structures. + const llvm::Type *ArgType; + if (IsRecursive) + ArgType = ConvertTypeRecursive(*I); + else + ArgType = ConvertType(*I); + PreferredArgTypes.push_back(ArgType); + } // Compute ABI information. getABIInfo().computeInfo(*FI, getContext(), TheModule.getContext(), diff --git a/lib/CodeGen/CodeGenTypes.cpp b/lib/CodeGen/CodeGenTypes.cpp index cf23c07394..6ff394e03c 100644 --- a/lib/CodeGen/CodeGenTypes.cpp +++ b/lib/CodeGen/CodeGenTypes.cpp @@ -46,7 +46,7 @@ CodeGenTypes::~CodeGenTypes() { const llvm::Type *CodeGenTypes::ConvertType(QualType T) { llvm::PATypeHolder Result = ConvertTypeRecursive(T); - // Any pointers that were converted defered evaluation of their pointee type, + // 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. @@ -284,7 +284,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(Ty); @@ -299,7 +300,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 +314,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(&Ty)) - return GetFunctionType(getFunctionInfo( - CanQual::CreateUnsafe(QualType(FPT,0))), - FPT->isVariadic()); - - const FunctionNoProtoType *FNPT = cast(&Ty); - return GetFunctionType(getFunctionInfo( - CanQual::CreateUnsafe(QualType(FNPT,0))), - true); + const CGFunctionInfo *FI; + bool isVariadic; + if (const FunctionProtoType *FPT = dyn_cast(&Ty)) { + FI = &getFunctionInfo( + CanQual::CreateUnsafe(QualType(FPT, 0)), + true /*Recursive*/); + isVariadic = FPT->isVariadic(); + } else { + const FunctionNoProtoType *FNPT = cast(&Ty); + FI = &getFunctionInfo( + CanQual::CreateUnsafe(QualType(FNPT, 0)), + true /*Recursive*/); + isVariadic = true; + } + + return GetFunctionType(*FI, isVariadic); } case Type::ObjCObject: diff --git a/lib/CodeGen/CodeGenTypes.h b/lib/CodeGen/CodeGenTypes.h index 674fe8f8b4..ff2c32904f 100644 --- a/lib/CodeGen/CodeGenTypes.h +++ b/lib/CodeGen/CodeGenTypes.h @@ -154,8 +154,11 @@ public: return getFunctionInfo(Ty->getResultType(), Args, Ty->getExtInfo()); } - const CGFunctionInfo &getFunctionInfo(CanQual Ty); - const CGFunctionInfo &getFunctionInfo(CanQual Ty); + + const CGFunctionInfo &getFunctionInfo(CanQual Ty, + bool IsRecursive = false); + const CGFunctionInfo &getFunctionInfo(CanQual Ty, + bool IsRecursive = false); // getFunctionInfo - Get the function info for a member function. const CGFunctionInfo &getFunctionInfo(const CXXRecordDecl *RD, @@ -176,7 +179,8 @@ public: /// \param ArgTys - must all actually be canonical as params const CGFunctionInfo &getFunctionInfo(CanQualType RetTy, const llvm::SmallVectorImpl &ArgTys, - const FunctionType::ExtInfo &Info); + const FunctionType::ExtInfo &Info, + bool IsRecursive = false); /// \brief Compute a new LLVM record layout object for the given record. CGRecordLayout *ComputeRecordLayout(const RecordDecl *D); diff --git a/lib/CodeGen/TargetInfo.cpp b/lib/CodeGen/TargetInfo.cpp index 2ba19f1096..c65f203715 100644 --- a/lib/CodeGen/TargetInfo.cpp +++ b/lib/CodeGen/TargetInfo.cpp @@ -830,8 +830,7 @@ X86_64ABIInfo::Class X86_64ABIInfo::merge(Class Accum, Class Field) { return SSE; } -void X86_64ABIInfo::classify(QualType Ty, - uint64_t OffsetBase, +void X86_64ABIInfo::classify(QualType Ty, uint64_t OffsetBase, Class &Lo, Class &Hi) const { // FIXME: This code can be simplified by introducing a simple value class for // Class pairs with appropriate constructor methods for the various diff --git a/test/CodeGen/decl.c b/test/CodeGen/decl.c index 7ffb7006b0..dcf120fd88 100644 --- a/test/CodeGen/decl.c +++ b/test/CodeGen/decl.c @@ -89,3 +89,16 @@ struct test7s { int a; int b; } test7[] = { struct test8s { int f0; char f1; } test8g = {}; +// PR7519 + +struct S { + void (*x) (struct S *); +}; + +extern struct S *global_dc; +void cp_diagnostic_starter(struct S *); + +void init_error(void) { + global_dc->x = cp_diagnostic_starter; +} + -- 2.40.0