[LLDB] Add a missing nullptr check for ClangImporter

This is not a possible code path in the Swift compiler, but LLDB has error paths
where ClangImporter could be null, and it has (for testing mostly) a setting to
disable ClangImporter entirely. When importing a Module with a header dependency
this crashes LLDB.

rdar://170007373
This commit is contained in:
Adrian Prantl
2026-02-09 15:42:51 -08:00
parent 45260c7de4
commit a8392c24eb

View File

@@ -152,7 +152,6 @@ ModuleFile::loadDependenciesForFileContext(const FileUnit *file,
SourceLoc diagLoc,
bool forTestable) {
ASTContext &ctx = getContext();
auto clangImporter = static_cast<ClangImporter *>(ctx.getClangModuleLoader());
ModuleDecl *M = file->getParentModule();
bool missingDependency = false;
@@ -163,6 +162,11 @@ ModuleFile::loadDependenciesForFileContext(const FileUnit *file,
assert(!dependency.isLoaded() && "already loaded?");
if (dependency.isHeader()) {
auto clangImporter =
static_cast<ClangImporter *>(ctx.getClangModuleLoader());
if (!clangImporter)
return Status::FailedToLoadBridgingHeader;
// The path may be empty if the file being loaded is a partial AST,
// and the current compiler invocation is a merge-modules step.
if (!dependency.Core.RawPath.empty()) {