[clang] [clang][modules] Avoid allocations when reading blob paths (PR #113984)

Ben Langmuir via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 29 09:54:42 PDT 2024


================
@@ -1341,9 +1341,22 @@ class ASTReader
   serialization::InputFile getInputFile(ModuleFile &F, unsigned ID,
                                         bool Complain = true);
 
+  /// Buffer we use as temporary storage backing resolved paths.
+  SmallString<256> PathBuf;
----------------
benlangmuir wrote:

@ChuanqiXu9 a static local would be global to the process instead of the compilation, which is unsafe if you have two independent `CompilerInstance` running in parallel.

@jansvoboda11 just an idea: would it help if we change the return type to some RAII object that takes temporary ownership of the path buffer? It would prevent the new kind of misuse: multiple calls to `ResolveImportedPath` with overlapping lifetimes for their results. It wouldn't prevent escaping a StringRef in callers (e.g. when calling `visitInputFile`), but that's also true today with `std::string`.

https://github.com/llvm/llvm-project/pull/113984


More information about the cfe-commits mailing list