diff options
author | Anthony Latsis <aqamoss3fan2010@gmail.com> | 2025-08-30 00:59:29 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-08-29 16:59:29 -0700 |
commit | 1532116a25573bfc12a43894928974cddb8660e1 (patch) | |
tree | 99f95ef1d4db05af33156cee0e1aabd8df4d0e3e /clang/lib/Frontend/CompilerInstance.cpp | |
parent | 8c8d1d45a6dcafb7d9255fe629d829ab5426ed7a (diff) | |
download | llvm-1532116a25573bfc12a43894928974cddb8660e1.zip llvm-1532116a25573bfc12a43894928974cddb8660e1.tar.gz llvm-1532116a25573bfc12a43894928974cddb8660e1.tar.bz2 |
[clang] Frontend: Destroy compiling compiler instance before read (#154455)
Upstreams https://github.com/swiftlang/llvm-project/pull/10943.
https://github.com/llvm/llvm-project/pull/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.
Co-authored-by: Ben Barham <ben_barham@apple.com>
Diffstat (limited to 'clang/lib/Frontend/CompilerInstance.cpp')
-rw-r--r-- | clang/lib/Frontend/CompilerInstance.cpp | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index 9f99edad..b2c566f 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -1473,16 +1473,18 @@ static bool compileModuleAndReadASTImpl(CompilerInstance &ImportingInstance, SourceLocation ModuleNameLoc, Module *Module, StringRef ModuleFileName) { - auto Instance = ImportingInstance.cloneForModuleCompile(ModuleNameLoc, Module, - ModuleFileName); - - if (!ImportingInstance.compileModule(ModuleNameLoc, - Module->getTopLevelModuleName(), - ModuleFileName, *Instance)) { - ImportingInstance.getDiagnostics().Report(ModuleNameLoc, - diag::err_module_not_built) - << Module->Name << SourceRange(ImportLoc, ModuleNameLoc); - return false; + { + auto Instance = ImportingInstance.cloneForModuleCompile( + ModuleNameLoc, Module, ModuleFileName); + + if (!ImportingInstance.compileModule(ModuleNameLoc, + Module->getTopLevelModuleName(), + ModuleFileName, *Instance)) { + ImportingInstance.getDiagnostics().Report(ModuleNameLoc, + diag::err_module_not_built) + << Module->Name << SourceRange(ImportLoc, ModuleNameLoc); + return false; + } } // The module is built successfully, we can update its timestamp now. |