Skip to content

Commit edb48df

Browse files
committed
[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.
1 parent 0276feb commit edb48df

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

lib/Sema/ImportResolution.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,11 @@ void swift::performImportResolutionForClangMacroBuffer(
347347
SF.ASTStage = SourceFile::ImportsResolved;
348348
}
349349

350+
static bool isSubmodule(const ModuleDecl* M) {
351+
auto clangMod = M->findUnderlyingClangModule();
352+
return clangMod && clangMod->Parent;
353+
}
354+
350355
//===----------------------------------------------------------------------===//
351356
// MARK: Import handling generally
352357
//===----------------------------------------------------------------------===//
@@ -395,7 +400,7 @@ void ImportResolver::bindImport(UnboundImport &&I) {
395400
I.validateOptions(topLevelModule, SF);
396401

397402
auto alreadyImportedTLM = [ID,this](const ModuleDecl *MD) {
398-
assert(!MD->findUnderlyingClangModule()->isSubModule());
403+
ASSERT(!isSubmodule(MD));
399404
// Scoped imports don't import all symbols from the module, so a scoped
400405
// import does not count the module as imported
401406
if (ID && isScopedImportKind(ID.get()->getImportKind()))
@@ -1613,11 +1618,6 @@ void ImportResolver::findCrossImports(
16131618
}
16141619
}
16151620

1616-
static bool isSubmodule(ModuleDecl* M) {
1617-
auto clangMod = M->findUnderlyingClangModule();
1618-
return clangMod && clangMod->Parent;
1619-
}
1620-
16211621
void ImportResolver::addCrossImportableModules(
16221622
AttributedImport<ImportedModule> importDesc) {
16231623
// FIXME: namelookup::getAllImports() doesn't quite do what we need (mainly

0 commit comments

Comments
 (0)