Skip to content

Commit 03f31d7

Browse files
committed
Fix an edge case where we may be attempting to finalize a CIWithContext instance that does not exist.
1 parent f6e8f31 commit 03f31d7

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,17 @@ DependencyScanningWorker::computeDependenciesByNameWithContextOrError(
245245

246246
llvm::Error
247247
DependencyScanningWorker::finalizeCompilerInstanceWithContextOrError() {
248-
bool Success = finalizeCompilerInstance();
249-
return CIWithContext->handleReturnStatus(Success);
248+
// TODO: this finalization interface is not ideal. Finalizing the
249+
// CIWithContext should happen automatically for successful scans, and
250+
// when errors occur.
251+
if (CIWithContext) {
252+
bool Success = finalizeCompilerInstance();
253+
return CIWithContext->handleReturnStatus(Success);
254+
}
255+
256+
// There is nothing to finalize, so the finalization should not report an
257+
// error.
258+
return llvm::Error::success();
250259
}
251260

252261
bool DependencyScanningWorker::initializeCompilerInstanceWithContext(
@@ -265,5 +274,6 @@ bool DependencyScanningWorker::computeDependenciesByNameWithContext(
265274
}
266275

267276
bool DependencyScanningWorker::finalizeCompilerInstance() {
277+
assert(CIWithContext && "Should not finalize without a CIWithContext");
268278
return CIWithContext->finalize();
269279
}

0 commit comments

Comments
 (0)