diff --git a/llvm/include/llvm/IR/Metadata.h b/llvm/include/llvm/IR/Metadata.h index 927729d063b9..dc7859885974 100644 --- a/llvm/include/llvm/IR/Metadata.h +++ b/llvm/include/llvm/IR/Metadata.h @@ -1303,7 +1303,13 @@ public: if (!Use) return; *Use = MD; - Use = nullptr; + + if (*Use) + MetadataTracking::track(*Use); + + Metadata *T = cast(this); + MetadataTracking::untrack(T); + assert(!Use && "Use is still being tracked despite being untracked!"); } }; diff --git a/llvm/tools/llvm-dis/llvm-dis.cpp b/llvm/tools/llvm-dis/llvm-dis.cpp index 0c1d723a7b10..82dbaa5e3c60 100644 --- a/llvm/tools/llvm-dis/llvm-dis.cpp +++ b/llvm/tools/llvm-dis/llvm-dis.cpp @@ -51,8 +51,13 @@ static cl::opt DontPrint("disable-output", cl::desc("Don't output the .ll file"), cl::Hidden); static cl::opt -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 + ShowAnnotations("show-annotations", + cl::desc("Add informational comments to the .ll file")); static cl::opt PreserveAssemblyUseListOrder( "preserve-ll-uselistorder", @@ -142,9 +147,9 @@ static ExitOnError ExitOnErr; static std::unique_ptr openInputFile(LLVMContext &Context) { std::unique_ptr MB = ExitOnErr(errorOrToExpected(MemoryBuffer::getFileOrSTDIN(InputFilename))); - std::unique_ptr M = - ExitOnErr(getOwningLazyBitcodeModule(std::move(MB), Context, - /*ShouldLazyLoadMetadata=*/true)); + std::unique_ptr M = ExitOnErr(getOwningLazyBitcodeModule( + std::move(MB), Context, + /*ShouldLazyLoadMetadata=*/true, SetImporting)); if (MaterializeMetadata) ExitOnErr(M->materializeMetadata()); else