Skip to content

Commit fffde38

Browse files
committed
Add error handling for compiler instance with context initialization and finalization.
1 parent c1ba410 commit fffde38

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

lib/DependencyScan/ScanDependencies.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,9 +1413,14 @@ performModuleScanImpl(
14131413
instance->getInvocation().getFrontendOptions().ParallelDependencyScan);
14141414

14151415
auto initError = scanner.initializeWorkerClangScanningTool();
1416-
// TODO: fix error check!
1417-
if (initError)
1418-
llvm::consumeError(std::move(initError));
1416+
if (initError) {
1417+
llvm::handleAllErrors(
1418+
std::move(initError), [&](const llvm::StringError &E) {
1419+
instance->getDiags().diagnose(
1420+
SourceLoc(), diag::clang_dependency_scan_error, E.getMessage());
1421+
});
1422+
return std::make_error_code(std::errc::invalid_argument);
1423+
}
14191424

14201425
// Identify imports of the main module and add an entry for it
14211426
// to the dependency graph.
@@ -1432,8 +1437,15 @@ performModuleScanImpl(
14321437
return std::make_error_code(std::errc::not_supported);
14331438

14341439
auto finError = scanner.finalizeWorkerClangScanningTool();
1435-
if (finError)
1436-
llvm::consumeError(std::move(finError));
1440+
if (finError) {
1441+
llvm::handleAllErrors(std::move(finError), [&](const llvm::StringError &E) {
1442+
instance->getDiags().diagnose(
1443+
SourceLoc(), diag::clang_dependency_scan_error, E.getMessage());
1444+
});
1445+
// TODO:it is not expected that the finialization fails. Maybe we should
1446+
// turn this into an assert.
1447+
return std::make_error_code(std::errc::not_supported);
1448+
}
14371449

14381450
auto topologicallySortedModuleList =
14391451
computeTopologicalSortOfExplicitDependencies(allModules, cache);

unittests/DependencyScan/ModuleDeps.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,6 @@ TEST_F(ScanTest, TestStressConcurrentDiagnostics) {
514514
ASSERT_FALSE(DependenciesOrErr.getError());
515515
auto Dependencies = DependenciesOrErr.get();
516516
auto Diagnostics = Dependencies->diagnostics;
517-
ASSERT_TRUE(Diagnostics->count > 100);
517+
ASSERT_TRUE(Diagnostics->count == 2);
518518
swiftscan_dependency_graph_dispose(Dependencies);
519519
}

0 commit comments

Comments
 (0)