[clang] [llvm] [clang] Support multiple in-process cc1 jobs in a ToolSession (PR #222531)
Alexandre Ganea via cfe-commits
cfe-commits at lists.llvm.org
Sun Oct 4 08:22:37 PDT 2026
================
@@ -283,15 +278,23 @@ int cc1_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) {
// Create the actual diagnostics engine.
Clang->createDiagnostics();
+ DiagsBuffer->FlushDiagnostics(Clang->getDiagnostics());
+ if (!Success)
+ return 1;
+
+ // Initialize process-global state only after the early-return paths above.
+ // Everything below reaches the corresponding cleanup before returning.
+ if (!Clang->getFrontendOpts().TimeTracePath.empty()) {
+ llvm::timeTraceProfilerInitialize(
+ Clang->getFrontendOpts().TimeTraceGranularity, Argv0,
+ Clang->getFrontendOpts().TimeTraceVerbose);
+ }
+
// Set an error handler, so that any LLVM backend diagnostics go through our
// error handler.
llvm::install_fatal_error_handler(LLVMErrorHandler,
----------------
aganea wrote:
Please use a `CrashRecoveryContextCleanupRegistrar` along with the installation of the fatal error handler, otherwise `llvm::remove_fatal_error_handler` below would never be called.
Additionally, I wonder if we shouln't stop further commands and consider the process as "contamined" after the first crash, in the same way LLD does with `canRunAgain`? Regardless of that choice, I would still do the fatal error cleanup anyway.
https://github.com/llvm/llvm-project/pull/222531
More information about the cfe-commits
mailing list