Skip to content

[ScanDependencies] Fix assertion failure when failed to scan header #73402

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions lib/ClangImporter/ClangModuleDependencyScanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,11 +493,8 @@ bool ClangImporter::addHeaderDependencies(
auto dependencies = clangScanningTool.getTranslationUnitDependencies(
commandLineArgs, workingDir, cache.getAlreadySeenClangModules(),
lookupModuleOutput);
if (!dependencies) {
// FIXME: Route this to a normal diagnostic.
llvm::logAllUnhandledErrors(dependencies.takeError(), llvm::errs());
if (!dependencies)
return dependencies.takeError();
}

// Record module dependencies for each new module we found.
auto bridgedDeps = bridgeClangModuleDependencies(
Expand Down Expand Up @@ -527,8 +524,15 @@ bool ClangImporter::addHeaderDependencies(
!targetModule.getBridgingHeader()->empty()) {
auto clangModuleDependencies =
scanHeaderDependencies(*targetModule.getBridgingHeader());
if (!clangModuleDependencies)
if (!clangModuleDependencies) {
// FIXME: Route this to a normal diagnostic.
llvm::logAllUnhandledErrors(clangModuleDependencies.takeError(),
llvm::errs());
Impl.SwiftContext.Diags.diagnose(
SourceLoc(), diag::clang_dependency_scan_error,
"failed to scan bridging header dependencies");
return true;
}
if (auto TreeID = clangModuleDependencies->IncludeTreeID)
targetModule.addBridgingHeaderIncludeTree(*TreeID);
recordBridgingHeaderOptions(targetModule, *clangModuleDependencies);
Expand Down
15 changes: 15 additions & 0 deletions test/ScanDependencies/clang_scan_error.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// REQUIRES: objc_interop
// RUN: %empty-directory(%t)
// RUN: split-file %s %t

// RUN: %target-swift-frontend -scan-dependencies -module-name Test %t/main.swift -import-objc-header %t/bridging.h \
// RUN: -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import -parse-stdlib \
// RUN: -o %t/deps.json -I %t -swift-version 5 2>&1 | %FileCheck %s

// CHECK: error: Clang dependency scanner failure: failed to scan bridging header dependencies

//--- bridging.h
#include "do-not-exist.h"

//--- main.swift
func test() {}