[cfe-commits] r46735 - /cfe/trunk/CodeGen/CodeGenTypes.cpp

Eli Friedman eli.friedman at gmail.com
Mon Feb 4 18:18:08 PST 2008


Author: efriedma
Date: Mon Feb  4 20:18:07 2008
New Revision: 46735

URL: http://llvm.org/viewvc/llvm-project?rev=46735&view=rev
Log:
Fix memory corruption from the type map being modified while a reference 
to a cell is being held.


Modified:
    cfe/trunk/CodeGen/CodeGenTypes.cpp

Modified: cfe/trunk/CodeGen/CodeGenTypes.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CodeGenTypes.cpp?rev=46735&r1=46734&r2=46735&view=diff

==============================================================================
--- cfe/trunk/CodeGen/CodeGenTypes.cpp (original)
+++ cfe/trunk/CodeGen/CodeGenTypes.cpp Mon Feb  4 20:18:07 2008
@@ -290,7 +290,7 @@
   case Type::Tagged:
     const TagType &TT = cast<TagType>(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 @@
       return ResultType;
     
     if (!TD->isDefinition()) {
-      ResultType = llvm::OpaqueType::get();  
+      ResultType = TagDeclTypes[TD] = llvm::OpaqueType::get();  
     } else if (TD->getKind() == Decl::Enum) {
       return ConvertType(cast<EnumDecl>(TD)->getIntegerType());
     } else if (TD->getKind() == Decl::Struct) {
@@ -335,7 +335,7 @@
 
       // 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 @@
 
         // Get llvm::StructType.
         CGRecordLayout *RLI = new CGRecordLayout(RO.getLLVMType());
-        ResultType = RLI->getLLVMType();
+        ResultType = TagDeclTypes[TD] = RLI->getLLVMType();
         CGRecordLayouts[ResultType] = RLI;
       } else {       
         std::vector<const llvm::Type*> Fields;
-        ResultType = llvm::StructType::get(Fields);
+        ResultType = TagDeclTypes[TD] = llvm::StructType::get(Fields);
       }
     } else {
       assert(0 && "FIXME: Implement tag decl kind!");





More information about the cfe-commits mailing list