From efb6d0dc3eafbcf4f8cd053138bd1abed1dda8d4 Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Sat, 6 Sep 2008 02:26:43 +0000 Subject: Key LLVM types for TagDecl's off of the clang Type, since there is now a many-to-one relationship between TagDecl's and types. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@55870 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CodeGenTypes.cpp | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) (limited to 'lib/CodeGen/CodeGenTypes.cpp') diff --git a/lib/CodeGen/CodeGenTypes.cpp b/lib/CodeGen/CodeGenTypes.cpp index e302f2b9ec..c91f801873 100644 --- a/lib/CodeGen/CodeGenTypes.cpp +++ b/lib/CodeGen/CodeGenTypes.cpp @@ -66,7 +66,7 @@ CodeGenTypes::CodeGenTypes(ASTContext &Ctx, llvm::Module& M, } CodeGenTypes::~CodeGenTypes() { - for(llvm::DenseMap::iterator + for(llvm::DenseMap::iterator I = CGRecordLayouts.begin(), E = CGRecordLayouts.end(); I != E; ++I) delete I->second; @@ -131,8 +131,10 @@ const llvm::Type *CodeGenTypes::ConvertTypeForMem(QualType T) { /// UpdateCompletedType - When we find the full definition for a TagDecl, /// replace the 'opaque' type we previously made for it if applicable. void CodeGenTypes::UpdateCompletedType(const TagDecl *TD) { - llvm::DenseMap::iterator TDTI = - TagDeclTypes.find(TD); + const Type *Key = + Context.getTagDeclType(const_cast(TD)).getTypePtr(); + llvm::DenseMap::iterator TDTI = + TagDeclTypes.find(Key); if (TDTI == TagDeclTypes.end()) return; // Remember the opaque LLVM type for this tagdecl. @@ -377,8 +379,12 @@ void CodeGenTypes::DecodeArgumentTypes(const FunctionTypeProto &FTP, /// ConvertTagDeclType - Lay out a tagged decl type like struct or union or /// enum. const llvm::Type *CodeGenTypes::ConvertTagDeclType(const TagDecl *TD) { - llvm::DenseMap::iterator TDTI = - TagDeclTypes.find(TD); + // TagDecl's are not necessarily unique, instead use the (clang) + // type connected to the decl. + const Type *Key = + Context.getTagDeclType(const_cast(TD)).getTypePtr(); + llvm::DenseMap::iterator TDTI = + TagDeclTypes.find(Key); // If we've already compiled this tag type, use the previous definition. if (TDTI != TagDeclTypes.end()) @@ -388,7 +394,7 @@ const llvm::Type *CodeGenTypes::ConvertTagDeclType(const TagDecl *TD) { // for this tagged decl. if (!TD->isDefinition()) { llvm::Type *ResultType = llvm::OpaqueType::get(); - TagDeclTypes.insert(std::make_pair(TD, ResultType)); + TagDeclTypes.insert(std::make_pair(Key, ResultType)); return ResultType; } @@ -406,7 +412,7 @@ const llvm::Type *CodeGenTypes::ConvertTagDeclType(const TagDecl *TD) { // Create new OpaqueType now for later use in case this is a recursive // type. This will later be refined to the actual type. llvm::PATypeHolder ResultHolder = llvm::OpaqueType::get(); - TagDeclTypes.insert(std::make_pair(TD, ResultHolder)); + TagDeclTypes.insert(std::make_pair(Key, ResultHolder)); const llvm::Type *ResultType; const RecordDecl *RD = cast(TD); @@ -417,8 +423,10 @@ const llvm::Type *CodeGenTypes::ConvertTagDeclType(const TagDecl *TD) { RO.layoutStructFields(Context.getASTRecordLayout(RD)); // Get llvm::StructType. - CGRecordLayouts[TD] = new CGRecordLayout(RO.getLLVMType(), - RO.getPaddingFields()); + const Type *Key = + Context.getTagDeclType(const_cast(TD)).getTypePtr(); + CGRecordLayouts[Key] = new CGRecordLayout(RO.getLLVMType(), + RO.getPaddingFields()); ResultType = RO.getLLVMType(); } else if (TD->isUnion()) { @@ -430,8 +438,10 @@ const llvm::Type *CodeGenTypes::ConvertTagDeclType(const TagDecl *TD) { RO.layoutUnionFields(Context.getASTRecordLayout(RD)); // Get llvm::StructType. - CGRecordLayouts[TD] = new CGRecordLayout(RO.getLLVMType(), - RO.getPaddingFields()); + const Type *Key = + Context.getTagDeclType(const_cast(TD)).getTypePtr(); + CGRecordLayouts[Key] = new CGRecordLayout(RO.getLLVMType(), + RO.getPaddingFields()); ResultType = RO.getLLVMType(); } else { ResultType = llvm::StructType::get(std::vector()); @@ -485,8 +495,10 @@ void CodeGenTypes::addBitFieldInfo(const FieldDecl *FD, unsigned Begin, /// getCGRecordLayout - Return record layout info for the given llvm::Type. const CGRecordLayout * CodeGenTypes::getCGRecordLayout(const TagDecl *TD) const { - llvm::DenseMap::iterator I - = CGRecordLayouts.find(TD); + const Type *Key = + Context.getTagDeclType(const_cast(TD)).getTypePtr(); + llvm::DenseMap::iterator I + = CGRecordLayouts.find(Key); assert (I != CGRecordLayouts.end() && "Unable to find record layout information for type"); return I->second; -- cgit v1.2.3-18-g5258