[clang] [clang modules] Setting `DebugCompilationDir` when it is safe to ignore current working directory (PR #128446)
Jan Svoboda via cfe-commits
cfe-commits at lists.llvm.org
Tue Feb 25 13:07:07 PST 2025
================
@@ -129,6 +129,26 @@ static void optimizeDiagnosticOpts(DiagnosticOptions &Opts,
Opts.Remarks.clear();
}
+static void optimizeCWD(FileSystemOptions &FSOpts, CodeGenOptions &CGOpts,
+ const std::string &CWD) {
+ FSOpts.WorkingDir.clear();
+ if (CGOpts.DwarfVersion) {
----------------
jansvoboda11 wrote:
Even if we don't take this branch (and therefore don't need to modify `CodeGenOptions`), we already might've made an unnecessary copy in the caller by calling `getMutCodeGenOpts()`. Can we pass the entire `CowCompilerInvocation &` into this function and then implement the logic like this?
```c++
if (CI.getCodeGenOpts().DwarfVersion) {
CI.getMutCodeGenOpts().DebugCompilationDir = ...;
}
```
`CodeGenOptions` is large (1824B) and making a copy for each module unnecessarily seems excessive.
Even if the optimization does kick in, it's still excessive to make a separate copy of `CodeGenOptions` for each module. We don't make any other module-specific changes to `CodeGenOptions` anywhere in the scanner, so they will all end up being identical copies. (At least for a single TU.) Maybe we could keep just two versions of `CodeGenOptions` for each TU: one with and one without `DebugCompilationDir`) and refer to either one or the other from all discovered modules' command lines. That's a bit more involved though and `CowCompilerInvocation` doesn't have a good API for this, so let's not sink time into it right now. Maybe leaving a FIXME here would be nice.
https://github.com/llvm/llvm-project/pull/128446
More information about the cfe-commits
mailing list