Fix a crasher where when we're attempting to replace a type
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.
llvm-svn: 202540
diff --git a/llvm/lib/IR/DIBuilder.cpp b/llvm/lib/IR/DIBuilder.cpp
index 4bb75bd..f5ccd5f 100644
--- a/llvm/lib/IR/DIBuilder.cpp
+++ b/llvm/lib/IR/DIBuilder.cpp
@@ -69,7 +69,10 @@
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 @@
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 @@
}
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 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;
}