[ImportResolution] Gracefully handle importing broken clang module

An assert checking the invariant of the module passed to
alreadyImportedTLM being a top-level module would dereference a null
pointer in the case where the clang module contained syntax errors,
since findUnderlyingClangModule would return null. Instead call the
bespoke isSubmodule function that already performs this null check.

This fixes the lldb test
lldb/test/API/lang/swift/clangimporter/expr_import/TestSwiftExprImport.py.
This commit is contained in:
Henrik G. Olsson
2025-09-19 15:42:26 -07:00
parent 0276febf41
commit edb48dff8c

View File

@@ -347,6 +347,11 @@ void swift::performImportResolutionForClangMacroBuffer(
SF.ASTStage = SourceFile::ImportsResolved;
}
static bool isSubmodule(const ModuleDecl* M) {
auto clangMod = M->findUnderlyingClangModule();
return clangMod && clangMod->Parent;
}
//===----------------------------------------------------------------------===//
// MARK: Import handling generally
//===----------------------------------------------------------------------===//
@@ -395,7 +400,7 @@ void ImportResolver::bindImport(UnboundImport &&I) {
I.validateOptions(topLevelModule, SF);
auto alreadyImportedTLM = [ID,this](const ModuleDecl *MD) {
assert(!MD->findUnderlyingClangModule()->isSubModule());
ASSERT(!isSubmodule(MD));
// Scoped imports don't import all symbols from the module, so a scoped
// import does not count the module as imported
if (ID && isScopedImportKind(ID.get()->getImportKind()))
@@ -1613,11 +1618,6 @@ void ImportResolver::findCrossImports(
}
}
static bool isSubmodule(ModuleDecl* M) {
auto clangMod = M->findUnderlyingClangModule();
return clangMod && clangMod->Parent;
}
void ImportResolver::addCrossImportableModules(
AttributedImport<ImportedModule> importDesc) {
// FIXME: namelookup::getAllImports() doesn't quite do what we need (mainly