diff --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp --- a/llvm/lib/LTO/LTO.cpp +++ b/llvm/lib/LTO/LTO.cpp @@ -1216,6 +1216,14 @@ MapVector &ModuleMap) { auto RunThinBackend = [&](AddStreamFn AddStream) { LTOLLVMContext BackendContext(Conf); + + // Don't leave the decision to use opaque pointers to the reader as we + // may be mixing bitcode using opaque and typed pointers and we can + // only upgrade typed pointers to opaque pointers. + if (!BackendContext.hasSetOpaquePointersValue()) { + BackendContext.setOpaquePointers(true); + } + Expected> MOrErr = BM.parseModule(BackendContext); if (!MOrErr) return MOrErr.takeError(); diff --git a/llvm/lib/LTO/LTOBackend.cpp b/llvm/lib/LTO/LTOBackend.cpp --- a/llvm/lib/LTO/LTOBackend.cpp +++ b/llvm/lib/LTO/LTOBackend.cpp @@ -419,6 +419,14 @@ CodegenThreadPool.async( [&](const SmallString<0> &BC, unsigned ThreadId) { LTOLLVMContext Ctx(C); + + // Don't leave the decision to use opaque pointers to the reader + // as we may be mixing bitcode using opaque and typed pointers and + // we can only upgrade typed pointers to opaque pointers. + if (!Ctx.hasSetOpaquePointersValue()) { + Ctx.setOpaquePointers(true); + } + Expected> MOrErr = parseBitcodeFile( MemoryBufferRef(StringRef(BC.data(), BC.size()), "ld-temp.o"), Ctx);