[clang] [CIR] Route MLIR diagnostics through clang::DiagnosticsEngine (PR #199297)

Konstantinos Parasyris via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 23 11:56:33 PDT 2026


================
@@ -52,6 +52,11 @@ void CIRGenerator::Initialize(ASTContext &astContext) {
   this->astContext = &astContext;
 
   mlirContext = std::make_unique<mlir::MLIRContext>();
+  // Disable MLIR multithreading: clang::DiagnosticsEngine is not thread-safe,
+  // and the per-context handler installed by CIRGenAction reports diagnostics
+  // straight through it. CIR's pass pipeline is short enough that we don't
+  // miss meaningful parallelism here.
+  mlirContext->disableMultithreading();
----------------
koparasy wrote:

I looked into this and I Enabled multithreading. It is Safe because the MLIR pass manager runs parallel op-pipelines through `mlir::ParallelDiagnosticHandler (Threading.h)`, which buffers each thread's diagnostics and re-emits them ( deterministically ordered ) on a single thread when it's destroyed. Only then do they reach the `CIRDiagnosticHandler` --> `clang::DiagnosticsEngine`, so the engine is never touched concurrently. Ordering also matches single-threaded output, so no interleaving regression.

https://github.com/llvm/llvm-project/pull/199297


More information about the cfe-commits mailing list