[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 09:19:05 PST 2025


================
@@ -492,8 +492,23 @@ static std::string getModuleContextHash(const ModuleDeps &MD,
   auto &FSOpts = const_cast<FileSystemOptions &>(CI.getFileSystemOpts());
   if (CWD && !IgnoreCWD)
     HashBuilder.add(*CWD);
-  else
+  else {
     FSOpts.WorkingDir.clear();
+    auto &CGOpts = const_cast<CodeGenOptions &>(CI.getCodeGenOpts());
----------------
jansvoboda11 wrote:

Please don't use `const_cast` here. This breaks invariants of `CowCompilerInvocation` that relies on clients using `getMut*Opts()` which create a copy behind the scenes whenever the `CodeGenOptions` instance is shared with other compiler invocation instances. I think a better place to do this mutation is in `makeCommonInvocationForModuleBuild()` (unless I'm missing some nuance here).

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


More information about the cfe-commits mailing list