diff --git a/llvm/include/llvm/LTO/Config.h b/llvm/include/llvm/LTO/Config.h --- a/llvm/include/llvm/LTO/Config.h +++ b/llvm/include/llvm/LTO/Config.h @@ -292,11 +292,14 @@ // FIXME: This should not be required as diagnostic handler is not callback. struct LTOLLVMContext : LLVMContext { + LTOLLVMContext() : LTOLLVMContext(Config()) {} + LTOLLVMContext(const Config &C) : DiagHandler(C.DiagHandler) { setDiscardValueNames(C.ShouldDiscardValueNames); enableDebugTypeODRUniquing(); - setDiagnosticHandler( - std::make_unique(&DiagHandler), true); + if (DiagHandler) + setDiagnosticHandler( + std::make_unique(&DiagHandler), true); if (!hasSetOpaquePointersValue()) setOpaquePointers(C.OpaquePointers); } diff --git a/llvm/lib/LTO/ThinLTOCodeGenerator.cpp b/llvm/lib/LTO/ThinLTOCodeGenerator.cpp --- a/llvm/lib/LTO/ThinLTOCodeGenerator.cpp +++ b/llvm/lib/LTO/ThinLTOCodeGenerator.cpp @@ -27,13 +27,14 @@ #include "llvm/Config/llvm-config.h" #include "llvm/IR/DebugInfo.h" #include "llvm/IR/DiagnosticPrinter.h" -#include "llvm/IR/LegacyPassManager.h" #include "llvm/IR/LLVMContext.h" #include "llvm/IR/LLVMRemarkStreamer.h" +#include "llvm/IR/LegacyPassManager.h" #include "llvm/IR/Mangler.h" #include "llvm/IR/PassTimingInfo.h" #include "llvm/IR/Verifier.h" #include "llvm/IRReader/IRReader.h" +#include "llvm/LTO/Config.h" #include "llvm/LTO/LTO.h" #include "llvm/LTO/SummaryBasedOptimizations.h" #include "llvm/MC/SubtargetFeature.h" @@ -69,6 +70,7 @@ #endif using namespace llvm; +using namespace lto; #define DEBUG_TYPE "thinlto" @@ -1159,7 +1161,7 @@ } } - LLVMContext Context; + LTOLLVMContext Context; Context.setDiscardValueNames(LTODiscardValueNames); Context.enableDebugTypeODRUniquing(); auto DiagFileOrErr = lto::setupLLVMOptimizationRemarks(