Skip to content

Commit ef9764a

Browse files
bnbarhamAnthonyLatsis
authored andcommitted
[clang] Frontend: Destroy compiling compiler instance before read
Upstreams #10943. 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 f3db0cb commit ef9764a

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
@@ -1473,16 +1473,18 @@ static bool compileModuleAndReadASTImpl(CompilerInstance &ImportingInstance,
14731473
SourceLocation ModuleNameLoc,
14741474
Module *Module,
14751475
StringRef ModuleFileName) {
1476-
auto Instance = ImportingInstance.cloneForModuleCompile(ModuleNameLoc, Module,
1477-
ModuleFileName);
1478-
1479-
if (!ImportingInstance.compileModule(ModuleNameLoc,
1480-
Module->getTopLevelModuleName(),
1481-
ModuleFileName, *Instance)) {
1482-
ImportingInstance.getDiagnostics().Report(ModuleNameLoc,
1483-
diag::err_module_not_built)
1484-
<< Module->Name << SourceRange(ImportLoc, ModuleNameLoc);
1485-
return false;
1476+
{
1477+
auto Instance = ImportingInstance.cloneForModuleCompile(ModuleNameLoc, Module,
1478+
ModuleFileName);
1479+
1480+
if (!ImportingInstance.compileModule(ModuleNameLoc,
1481+
Module->getTopLevelModuleName(),
1482+
ModuleFileName, *Instance)) {
1483+
ImportingInstance.getDiagnostics().Report(ModuleNameLoc,
1484+
diag::err_module_not_built)
1485+
<< Module->Name << SourceRange(ImportLoc, ModuleNameLoc);
1486+
return false;
1487+
}
14861488
}
14871489

14881490
// The module is built successfully, we can update its timestamp now.

0 commit comments

Comments
 (0)