From 0a827eb82193cb2d2bb62974414327288dde0c26 Mon Sep 17 00:00:00 2001 From: Jan Svoboda Date: Thu, 24 Apr 2025 11:30:08 -0700 Subject: [PATCH] [clang] Enable making `CompilerInstance` output backend thread-safe --- clang/lib/Frontend/CompilerInstance.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index 93086494b8f6d..887e9321b7f73 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -1418,10 +1418,15 @@ std::unique_ptr CompilerInstance::cloneForModuleCompileImpl( auto WrapGenModuleAction = getGenModuleActionWrapper(); Instance.setGenModuleActionWrapper(WrapGenModuleAction); - // Share an output manager. assert(hasOutputBackend() && "Expected an output manager to already be set up"); - Instance.setOutputBackend(&getOutputBackend()); + if (ThreadSafeConfig) { + // Create a clone of the existing output (pointing to the same destination). + Instance.setOutputBackend(getOutputBackend().clone()); + } else { + // Share the existing output manager. + Instance.setOutputBackend(&getOutputBackend()); + } if (ThreadSafeConfig) { Instance.setModuleDepCollector(ThreadSafeConfig->getModuleDepCollector());