OSDN Git Service

Fix a crasher where when we're attempting to replace a type
authorEric Christopher <echristo@gmail.com>
Fri, 28 Feb 2014 21:27:57 +0000 (21:27 +0000)
committerEric Christopher <echristo@gmail.com>
Fri, 28 Feb 2014 21:27:57 +0000 (21:27 +0000)
during the finalization for CGDebugInfo in clang we would RAUW
a type and it would result in a corrupted MDNode for an
imported declaration.

Testcase pending as reducing has been difficult.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@202540 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/DIBuilder.h
lib/IR/DIBuilder.cpp

index d47bae5..ba7bca7 100644 (file)
@@ -72,7 +72,7 @@ namespace llvm {
     SmallVector<TrackingVH<MDNode>, 4> AllRetainTypes;
     SmallVector<Value *, 4> AllSubprograms;
     SmallVector<Value *, 4> AllGVs;
-    SmallVector<Value *, 4> AllImportedModules;
+    SmallVector<TrackingVH<MDNode>, 4> AllImportedModules;
 
     // Private use for multiple types of template parameters.
     DITemplateValueParameter
index 4bb75bd..f5ccd5f 100644 (file)
@@ -69,7 +69,10 @@ void DIBuilder::finalize() {
   DIArray GVs = getOrCreateArray(AllGVs);
   DIType(TempGVs).replaceAllUsesWith(GVs);
 
-  DIArray IMs = getOrCreateArray(AllImportedModules);
+  SmallVector<Value *, 16> RetainValuesI;
+  for (unsigned I = 0, E = AllImportedModules.size(); I < E; I++)
+    RetainValuesI.push_back(AllImportedModules[I]);
+  DIArray IMs = getOrCreateArray(RetainValuesI);
   DIType(TempImportedModules).replaceAllUsesWith(IMs);
 }
 
@@ -145,7 +148,7 @@ DICompileUnit DIBuilder::createCompileUnit(unsigned Lang, StringRef Filename,
 static DIImportedEntity
 createImportedModule(LLVMContext &C, DIScope Context, DIDescriptor NS,
                      unsigned Line, StringRef Name,
-                     SmallVectorImpl<Value *> &AllImportedModules) {
+                     SmallVectorImpl<TrackingVH<MDNode>> &AllImportedModules) {
   const MDNode *R;
   if (Name.empty()) {
     Value *Elts[] = {
@@ -167,7 +170,7 @@ createImportedModule(LLVMContext &C, DIScope Context, DIDescriptor NS,
   }
   DIImportedEntity M(R);
   assert(M.Verify() && "Imported module should be valid");
-  AllImportedModules.push_back(M);
+  AllImportedModules.push_back(TrackingVH<MDNode>(M));
   return M;
 }
 
@@ -197,7 +200,7 @@ DIImportedEntity DIBuilder::createImportedDeclaration(DIScope Context,
   };
   DIImportedEntity M(MDNode::get(VMContext, Elts));
   assert(M.Verify() && "Imported module should be valid");
-  AllImportedModules.push_back(M);
+  AllImportedModules.push_back(TrackingVH<MDNode>(M));
   return M;
 }