From: Eli Friedman Date: Tue, 5 Feb 2008 02:18:07 +0000 (+0000) Subject: Fix memory corruption from the type map being modified while a reference X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0ded75bc88b40607aa5baced6e4729774ed2df56;p=clang Fix memory corruption from the type map being modified while a reference to a cell is being held. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@46735 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/CodeGen/CodeGenTypes.cpp b/CodeGen/CodeGenTypes.cpp index 25354eb945..f3510d4595 100644 --- a/CodeGen/CodeGenTypes.cpp +++ b/CodeGen/CodeGenTypes.cpp @@ -290,7 +290,7 @@ const llvm::Type *CodeGenTypes::ConvertNewType(QualType T) { case Type::Tagged: const TagType &TT = cast(Ty); const TagDecl *TD = TT.getDecl(); - llvm::Type *&ResultType = TagDeclTypes[TD]; + llvm::Type *ResultType = TagDeclTypes[TD]; // If corresponding llvm type is not a opaque struct type // then use it. @@ -298,7 +298,7 @@ const llvm::Type *CodeGenTypes::ConvertNewType(QualType T) { return ResultType; if (!TD->isDefinition()) { - ResultType = llvm::OpaqueType::get(); + ResultType = TagDeclTypes[TD] = llvm::OpaqueType::get(); } else if (TD->getKind() == Decl::Enum) { return ConvertType(cast(TD)->getIntegerType()); } else if (TD->getKind() == Decl::Struct) { @@ -335,7 +335,7 @@ const llvm::Type *CodeGenTypes::ConvertNewType(QualType T) { // Get llvm::StructType. CGRecordLayout *RLI = new CGRecordLayout(RO.getLLVMType()); - ResultType = RLI->getLLVMType(); + ResultType = TagDeclTypes[TD] = RLI->getLLVMType(); CGRecordLayouts[ResultType] = RLI; // Refine any OpaqueType associated with this RecordDecl. @@ -358,11 +358,11 @@ const llvm::Type *CodeGenTypes::ConvertNewType(QualType T) { // Get llvm::StructType. CGRecordLayout *RLI = new CGRecordLayout(RO.getLLVMType()); - ResultType = RLI->getLLVMType(); + ResultType = TagDeclTypes[TD] = RLI->getLLVMType(); CGRecordLayouts[ResultType] = RLI; } else { std::vector Fields; - ResultType = llvm::StructType::get(Fields); + ResultType = TagDeclTypes[TD] = llvm::StructType::get(Fields); } } else { assert(0 && "FIXME: Implement tag decl kind!");