From 03f31d731a730b57e95d94c4ce06a65974d4e8f7 Mon Sep 17 00:00:00 2001 From: Qiongsi Wu Date: Fri, 19 Dec 2025 10:02:27 -0800 Subject: [PATCH] Fix an edge case where we may be attempting to finalize a CIWithContext instance that does not exist. --- .../DependencyScanningWorker.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp b/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp index ceb8dd3e2c794..6d4359f00e2e0 100644 --- a/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp +++ b/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp @@ -245,8 +245,17 @@ DependencyScanningWorker::computeDependenciesByNameWithContextOrError( llvm::Error DependencyScanningWorker::finalizeCompilerInstanceWithContextOrError() { - bool Success = finalizeCompilerInstance(); - return CIWithContext->handleReturnStatus(Success); + // TODO: this finalization interface is not ideal. Finalizing the + // CIWithContext should happen automatically for successful scans, and + // when errors occur. + if (CIWithContext) { + bool Success = finalizeCompilerInstance(); + return CIWithContext->handleReturnStatus(Success); + } + + // There is nothing to finalize, so the finalization should not report an + // error. + return llvm::Error::success(); } bool DependencyScanningWorker::initializeCompilerInstanceWithContext( @@ -265,5 +274,6 @@ bool DependencyScanningWorker::computeDependenciesByNameWithContext( } bool DependencyScanningWorker::finalizeCompilerInstance() { + assert(CIWithContext && "Should not finalize without a CIWithContext"); return CIWithContext->finalize(); }