From: Chris Lattner Date: Tue, 5 Feb 2008 06:55:31 +0000 (+0000) Subject: Change the key of CGRecordLayouts from being an llvm type* to being a decl*. LLVM X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=af31913e48c96fddb45a0fd33f25617546502cbb;p=clang Change the key of CGRecordLayouts from being an llvm type* to being a decl*. LLVM Type*'s can change as types are refined, so we can't use them as a stable key in the map. Decls don't change, so use them instead. This patch was written by Anders, but he's too shy to commit it himself :) git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@46743 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/CodeGen/CGExprConstant.cpp b/CodeGen/CGExprConstant.cpp index fbf65aa59b..f72994d508 100644 --- a/CodeGen/CGExprConstant.cpp +++ b/CodeGen/CGExprConstant.cpp @@ -104,8 +104,9 @@ public: llvm::Constant *EmitStructInitialization(InitListExpr *ILE, const llvm::StructType *SType) { + TagDecl *TD = ILE->getType()->getAsRecordType()->getDecl(); std::vector Elts; - const CGRecordLayout *CGR = CGM.getTypes().getCGRecordLayout(SType); + const CGRecordLayout *CGR = CGM.getTypes().getCGRecordLayout(TD); unsigned NumInitElements = ILE->getNumInits(); unsigned NumElements = SType->getNumElements(); diff --git a/CodeGen/CodeGenFunction.cpp b/CodeGen/CodeGenFunction.cpp index 98d0b01ad5..dc31a27945 100644 --- a/CodeGen/CodeGenFunction.cpp +++ b/CodeGen/CodeGenFunction.cpp @@ -139,14 +139,11 @@ void CodeGenFunction::StartBlock(const char *N) { /// getCGRecordLayout - Return record layout info. const CGRecordLayout *CodeGenFunction::getCGRecordLayout(CodeGenTypes &CGT, - QualType RTy) { - assert (isa(RTy) - && "Unexpected type. RecordType expected here."); + QualType Ty) { + const RecordType *RTy = Ty->getAsRecordType(); + assert (RTy && "Unexpected type. RecordType expected here."); - const llvm::Type *Ty = ConvertType(RTy); - assert (Ty && "Unable to find llvm::Type"); - - return CGT.getCGRecordLayout(Ty); + return CGT.getCGRecordLayout(RTy->getDecl()); } /// WarnUnsupported - Print out a warning that codegen doesn't support the diff --git a/CodeGen/CodeGenTypes.cpp b/CodeGen/CodeGenTypes.cpp index 06ec4679bc..97fc61d4ac 100644 --- a/CodeGen/CodeGenTypes.cpp +++ b/CodeGen/CodeGenTypes.cpp @@ -84,7 +84,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; @@ -332,7 +332,7 @@ const llvm::Type *CodeGenTypes::ConvertNewType(QualType T) { CGRecordLayout *RLI = new CGRecordLayout(RO.getLLVMType(), RO.getPaddingFields()); ResultType = TagDeclTypes[TD] = RLI->getLLVMType(); - CGRecordLayouts[ResultType] = RLI; + CGRecordLayouts[TD] = RLI; // Refine any OpaqueType associated with this RecordDecl. OpaqueTy->refineAbstractTypeTo(ResultType); @@ -356,7 +356,7 @@ const llvm::Type *CodeGenTypes::ConvertNewType(QualType T) { CGRecordLayout *RLI = new CGRecordLayout(RO.getLLVMType(), RO.getPaddingFields()); ResultType = TagDeclTypes[TD] = RLI->getLLVMType(); - CGRecordLayouts[ResultType] = RLI; + CGRecordLayouts[TD] = RLI; } else { std::vector Fields; ResultType = TagDeclTypes[TD] = llvm::StructType::get(Fields); @@ -436,9 +436,9 @@ void CodeGenTypes::addBitFieldInfo(const FieldDecl *FD, unsigned Begin, /// getCGRecordLayout - Return record layout info for the given llvm::Type. const CGRecordLayout * -CodeGenTypes::getCGRecordLayout(const llvm::Type* Ty) const { - llvm::DenseMap::iterator I - = CGRecordLayouts.find(Ty); +CodeGenTypes::getCGRecordLayout(const TagDecl *TD) const { + llvm::DenseMap::iterator I + = CGRecordLayouts.find(TD); assert (I != CGRecordLayouts.end() && "Unable to find record layout information for type"); return I->second; diff --git a/CodeGen/CodeGenTypes.h b/CodeGen/CodeGenTypes.h index 2ca3d3478c..0da71ca029 100644 --- a/CodeGen/CodeGenTypes.h +++ b/CodeGen/CodeGenTypes.h @@ -81,7 +81,7 @@ class CodeGenTypes { /// record layout info. /// FIXME : If CGRecordLayout is less than 16 bytes then use /// inline it in the map. - llvm::DenseMap CGRecordLayouts; + llvm::DenseMap CGRecordLayouts; /// FieldInfo - This maps struct field with corresponding llvm struct type /// field no. This info is populated by record organizer. @@ -136,7 +136,7 @@ public: const llvm::Type *ConvertTypeForMem(QualType T); - const CGRecordLayout *getCGRecordLayout(const llvm::Type*) const; + const CGRecordLayout *getCGRecordLayout(const TagDecl*) const; /// getLLVMFieldNo - Return llvm::StructType element number /// that corresponds to the field FD.