Skip to content

Commit 3fec80b

Browse files
committed
[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 771c93e commit 3fec80b

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
@@ -1643,16 +1643,18 @@ static bool compileModuleAndReadASTImpl(CompilerInstance &ImportingInstance,
16431643
SourceLocation ModuleNameLoc,
16441644
Module *Module,
16451645
StringRef ModuleFileName) {
1646-
auto Instance = ImportingInstance.cloneForModuleCompile(ModuleNameLoc, Module,
1647-
ModuleFileName);
1648-
1649-
if (!ImportingInstance.compileModule(ModuleNameLoc,
1650-
Module->getTopLevelModuleName(),
1651-
ModuleFileName, *Instance)) {
1652-
ImportingInstance.getDiagnostics().Report(ModuleNameLoc,
1653-
diag::err_module_not_built)
1654-
<< Module->Name << SourceRange(ImportLoc, ModuleNameLoc);
1655-
return false;
1646+
{
1647+
auto Instance = ImportingInstance.cloneForModuleCompile(ModuleNameLoc, Module,
1648+
ModuleFileName);
1649+
1650+
if (!ImportingInstance.compileModule(ModuleNameLoc,
1651+
Module->getTopLevelModuleName(),
1652+
ModuleFileName, *Instance)) {
1653+
ImportingInstance.getDiagnostics().Report(ModuleNameLoc,
1654+
diag::err_module_not_built)
1655+
<< Module->Name << SourceRange(ImportLoc, ModuleNameLoc);
1656+
return false;
1657+
}
16561658
}
16571659

16581660
return readASTAfterCompileModule(ImportingInstance, ImportLoc, ModuleNameLoc,

0 commit comments

Comments
 (0)