]> granicus.if.org Git - llvm/commitdiff
[ThinLTO] Fix ThinLTO crash while destroying context
authorCharles Saternos <charles.saternos@gmail.com>
Tue, 15 Aug 2017 22:23:44 +0000 (22:23 +0000)
committerCharles Saternos <charles.saternos@gmail.com>
Tue, 15 Aug 2017 22:23:44 +0000 (22:23 +0000)
Fix for PR32763

An assert that checks if a Ref was untracked fails during ThinLTO context cleanup. The issue is because lazy loading temporary nodes didn't properly track ValueAsMetadata nodes. This patch ensures that the temporary nodes are properly tracked when they're replaced with the value.

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

include/llvm/IR/Metadata.h
tools/llvm-dis/llvm-dis.cpp

index 927729d063b91982520ff82e9c66f2b1dc4ccd6e..dc78598859746de4f5c5c87b54a07b8e8cad9d61 100644 (file)
@@ -1303,7 +1303,13 @@ public:
     if (!Use)
       return;
     *Use = MD;
-    Use = nullptr;
+
+    if (*Use)
+      MetadataTracking::track(*Use);
+
+    Metadata *T = cast<Metadata>(this);
+    MetadataTracking::untrack(T);
+    assert(!Use && "Use is still being tracked despite being untracked!");
   }
 };
 
index 0c1d723a7b1002bc668d6b2771f3eb0cd408596a..82dbaa5e3c60c285521dc0ec8f016492322a0e80 100644 (file)
@@ -51,8 +51,13 @@ static cl::opt<bool>
 DontPrint("disable-output", cl::desc("Don't output the .ll file"), cl::Hidden);
 
 static cl::opt<bool>
-ShowAnnotations("show-annotations",
-                cl::desc("Add informational comments to the .ll file"));
+    SetImporting("set-importing",
+                 cl::desc("Set lazy loading to pretend to import a module"),
+                 cl::Hidden);
+
+static cl::opt<bool>
+    ShowAnnotations("show-annotations",
+                    cl::desc("Add informational comments to the .ll file"));
 
 static cl::opt<bool> PreserveAssemblyUseListOrder(
     "preserve-ll-uselistorder",
@@ -142,9 +147,9 @@ static ExitOnError ExitOnErr;
 static std::unique_ptr<Module> openInputFile(LLVMContext &Context) {
   std::unique_ptr<MemoryBuffer> MB =
       ExitOnErr(errorOrToExpected(MemoryBuffer::getFileOrSTDIN(InputFilename)));
-  std::unique_ptr<Module> M =
-      ExitOnErr(getOwningLazyBitcodeModule(std::move(MB), Context,
-                                           /*ShouldLazyLoadMetadata=*/true));
+  std::unique_ptr<Module> M = ExitOnErr(getOwningLazyBitcodeModule(
+      std::move(MB), Context,
+      /*ShouldLazyLoadMetadata=*/true, SetImporting));
   if (MaterializeMetadata)
     ExitOnErr(M->materializeMetadata());
   else