[clang] [Clang][Driver][NFC] Generalize addDebugCompDirArg to addCompDirArg (PR #247135)

Vitaly Buka via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 30 21:02:59 PST 2026


================
@@ -231,23 +231,22 @@ static bool ShouldEnableAutolink(const ArgList &Args, const ToolChain &TC,
                       Default);
 }
 
-/// Add a CC1 option to specify the debug compilation directory.
-static const char *addDebugCompDirArg(const ArgList &Args,
-                                      ArgStringList &CmdArgs,
-                                      const llvm::vfs::FileSystem &VFS) {
-  std::string DebugCompDir;
-  if (Arg *A = Args.getLastArg(options::OPT_ffile_compilation_dir_EQ,
-                               options::OPT_fdebug_compilation_dir_EQ))
-    DebugCompDir = A->getValue();
-
-  if (DebugCompDir.empty()) {
+/// Add a CC1 option to specify a compilation directory.
+static const char *addCompDirArg(const ArgList &Args, ArgStringList &CmdArgs,
+                                 const llvm::vfs::FileSystem &VFS,
+                                 llvm::opt::OptSpecifier Opt,
+                                 StringRef CC1Flag) {
+  std::string CompDir;
+  if (Arg *A = Args.getLastArg(options::OPT_ffile_compilation_dir_EQ, Opt))
+    CompDir = A->getValue();
+
+  if (CompDir.empty()) {
     if (llvm::ErrorOr<std::string> CWD = VFS.getCurrentWorkingDirectory())
-      DebugCompDir = std::move(*CWD);
+      CompDir = std::move(*CWD);
     else
       return nullptr;
   }
-  CmdArgs.push_back(
-      Args.MakeArgString("-fdebug-compilation-dir=" + DebugCompDir));
+  CmdArgs.push_back(Args.MakeArgString(Twine(CC1Flag) + CompDir));
   StringRef Path(CmdArgs.back());
   return Path.substr(Path.find('=') + 1).data();
----------------
vitalybuka wrote:

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

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


More information about the cfe-commits mailing list