Skip to content

Commit b64505a

Browse files
bnbarhamAnthonyLatsis
authored andcommitted
[Frontend] Destroy compiling compiler instance before read
llvm#134887 added a clone for the compiler instance in `compileModuleAndReadASTImpl`, which would then be destroyed *after* the corresponding read in the importing instance. Swift has a `SwiftNameLookupExtension` module extension which updates (effectively) global state - populating the lookup table for a module on read and removing it when the module is destroyed. With newly cloned instance, we would then see: - Module compiled with cloned instance - Module read with importing instance - Lookup table for that module added - Cloned instance destroyed - Module from that cloned instance destroyed - Lookup table for that module name removed Depending on the original semantics is incredibly fragile, but for now it's good enough to ensure that the read in the importing instance is after the cloned instanced is destroyed. Ideally we'd only ever add to the lookup tables in the original importing instance, never its clones.
1 parent ae0c681 commit b64505a

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

clang/lib/Frontend/CompilerInstance.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1655,16 +1655,18 @@ static bool compileModuleAndReadASTImpl(CompilerInstance &ImportingInstance,
16551655
SourceLocation ModuleNameLoc,
16561656
Module *Module,
16571657
StringRef ModuleFileName) {
1658-
auto Instance = ImportingInstance.cloneForModuleCompile(ModuleNameLoc, Module,
1659-
ModuleFileName);
1660-
1661-
if (!ImportingInstance.compileModule(ModuleNameLoc,
1662-
Module->getTopLevelModuleName(),
1663-
ModuleFileName, *Instance)) {
1664-
ImportingInstance.getDiagnostics().Report(ModuleNameLoc,
1665-
diag::err_module_not_built)
1666-
<< Module->Name << SourceRange(ImportLoc, ModuleNameLoc);
1667-
return false;
1658+
{
1659+
auto Instance = ImportingInstance.cloneForModuleCompile(ModuleNameLoc, Module,
1660+
ModuleFileName);
1661+
1662+
if (!ImportingInstance.compileModule(ModuleNameLoc,
1663+
Module->getTopLevelModuleName(),
1664+
ModuleFileName, *Instance)) {
1665+
ImportingInstance.getDiagnostics().Report(ModuleNameLoc,
1666+
diag::err_module_not_built)
1667+
<< Module->Name << SourceRange(ImportLoc, ModuleNameLoc);
1668+
return false;
1669+
}
16681670
}
16691671

16701672
return readASTAfterCompileModule(ImportingInstance, ImportLoc, ModuleNameLoc,

0 commit comments

Comments
 (0)