diff --git a/CodeGen/CodeGenTypes.cpp b/CodeGen/CodeGenTypes.cpp index 06d960927b..1fd09e974a 100644 --- a/CodeGen/CodeGenTypes.cpp +++ b/CodeGen/CodeGenTypes.cpp @@ -75,16 +75,16 @@ CodeGenTypes::~CodeGenTypes() { /// ConvertType - Convert the specified type to its LLVM form. const llvm::Type *CodeGenTypes::ConvertType(QualType T) { // See if type is already cached. - llvm::DenseMap::iterator + llvm::DenseMap::iterator I = TypeHolderMap.find(T.getTypePtr()); if (I != TypeHolderMap.end()) { - llvm::PATypeHolder *PAT = I->second; - return PAT->get(); + llvm::PATypeHolder PAT = I->second; + return PAT.get(); } const llvm::Type *ResultType = ConvertNewType(T); - llvm::PATypeHolder *PAT = new llvm::PATypeHolder(ResultType); - TypeHolderMap[T.getTypePtr()] = PAT; + TypeHolderMap.insert(std::make_pair(T.getTypePtr(), + llvm::PATypeHolder(ResultType))); return ResultType; } @@ -187,7 +187,9 @@ const llvm::Type *CodeGenTypes::ConvertNewType(QualType T) { if (!ResultType->isFirstClassType() && ResultType != llvm::Type::VoidTy) { const llvm::Type *RType = llvm::PointerType::get(ResultType); QualType RTy = Context.getPointerType(FP.getResultType()); - TypeHolderMap[RTy.getTypePtr()] = new llvm::PATypeHolder(RType); + TypeHolderMap.insert(std::make_pair(RTy.getTypePtr(), + llvm::PATypeHolder(RType))); + ArgTys.push_back(RType); ResultType = llvm::Type::VoidTy; } @@ -237,8 +239,8 @@ const llvm::Type *CodeGenTypes::ConvertNewType(QualType T) { // Reevaluate this when performance analyis finds tons of opaque types. llvm::OpaqueType *OpaqueTy = llvm::OpaqueType::get(); RecordTypesToResolve[RD] = OpaqueTy; - QualType Opq; - TypeHolderMap[Opq.getTypePtr()] = new llvm::PATypeHolder(OpaqueTy); + TypeHolderMap.insert(std::make_pair(T.getTypePtr(), + llvm::PATypeHolder(OpaqueTy))); // Layout fields. RecordOrganizer RO; @@ -304,7 +306,9 @@ void CodeGenTypes::DecodeArgumentTypes(const FunctionTypeProto &FTP, else { QualType PTy = Context.getPointerType(FTP.getArgType(i)); const llvm::Type *PtrTy = llvm::PointerType::get(Ty); - TypeHolderMap[PTy.getTypePtr()] = new llvm::PATypeHolder(PtrTy); + TypeHolderMap.insert(std::make_pair(PTy.getTypePtr(), + llvm::PATypeHolder(PtrTy))); + ArgTys.push_back(PtrTy); } } diff --git a/CodeGen/CodeGenTypes.h b/CodeGen/CodeGenTypes.h index a6e13c4ebf..95aea85c8e 100644 --- a/CodeGen/CodeGenTypes.h +++ b/CodeGen/CodeGenTypes.h @@ -83,7 +83,7 @@ class CodeGenTypes { /// and maps llvm::Types to corresponding clang::Type. llvm::PATypeHolder is /// used instead of llvm::Type because it allows us to bypass potential /// dangling type pointers due to type refinement on llvm side. - llvm::DenseMap TypeHolderMap; + llvm::DenseMap TypeHolderMap; /// ConvertNewType - Convert type T into a llvm::Type. Do not use this /// method directly because it does not do any type caching. This method