Skip to content

Commit 30ea6ec

Browse files
committed
Restrict RemoteASTTypeBuilder::findModule() to the list of loaded modules.
LLDB uses RemoteAST for its per-module SwiftASTContext. Importing external modules here could permanently damage this context, for example when a Clang import fails because of missing header search options. To avoid this situation, restrict RemoteAST's access to only the module's transitive closure of imports. Triggering this situation needs two independent Swift compilation units. An accompanying testcase (Swift/RemoteASTImport.test) has been added to LLDB. rdar://problem/40950542
1 parent e840330 commit 30ea6ec

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

lib/RemoteAST/RemoteAST.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,13 @@ RemoteASTTypeBuilder::createNominalTypeDecl(const Demangle::NodePointer &node) {
570570
ModuleDecl *RemoteASTTypeBuilder::findModule(const Demangle::NodePointer &node){
571571
assert(node->getKind() == Demangle::Node::Kind::Module);
572572
const auto &moduleName = node->getText();
573-
return Ctx.getModuleByName(moduleName);
573+
// Intentionally using getLoadedModule() instead of getModuleByName() here.
574+
// LLDB uses RemoteAST for its per-module SwiftASTContext. Importing external
575+
// modules here could permanently damage this context, for example when a
576+
// Clang import fails because of missing header search options. To avoid this
577+
// situation, restrict RemoteAST's access to only the module's transitive
578+
// closure of imports.
579+
return Ctx.getLoadedModule(Ctx.getIdentifier(moduleName));
574580
}
575581

576582
Demangle::NodePointer

0 commit comments

Comments
 (0)