[clang] [clang-cl] Accept `cl`-style output arguments (`/Fo`, `-Fo`) for `--fmodule-output` (PR #121046)

Sharadh Rajaraman via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 7 13:25:41 PST 2025


https://github.com/sharadhr updated https://github.com/llvm/llvm-project/pull/121046

>From b6bda7bd5980f3ff9bb9bd680846eb1bb05ac7c7 Mon Sep 17 00:00:00 2001
From: Sharadh Rajaraman <r.sharadh at outlook.sg>
Date: Fri, 7 Feb 2025 21:24:12 +0000
Subject: [PATCH] Accept /Fo and -Fo in `-fmodule-output` when running under CL
 mode

---
 clang/lib/Driver/Driver.cpp | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 4d9492ea08f6479..36749a90750010a 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -6097,10 +6097,29 @@ const char *Driver::GetNamedOutputPath(Compilation &C, const JobAction &JA,
   }
 
   llvm::PrettyStackTraceString CrashInfo("Computing output path");
+
   // Output to a user requested destination?
   if (AtTopLevel && !isa<DsymutilJobAction>(JA) && !isa<VerifyJobAction>(JA)) {
-    if (Arg *FinalOutput = C.getArgs().getLastArg(options::OPT_o))
+    bool IsCLNonPCH =
+        IsCLMode() && !C.getArgs().hasArg(options::OPT__SLASH_Yc) &&
+        (isa<PreprocessJobAction>(JA) || isa<PrecompileJobAction>(JA));
+    bool HasAnyOutputArg = C.getArgs().hasArg(
+        options::OPT_o, options::OPT__SLASH_Fo, options::OPT__SLASH_Fo_COLON);
+
+    Arg *FinalOutput = nullptr;
+    if (IsCLNonPCH && HasAnyOutputArg) {
+      FinalOutput = C.getArgs().getLastArg(
+          options::OPT_o, options::OPT__SLASH_Fo, options::OPT__SLASH_Fo_COLON);
+    } else if (IsCLNonPCH) {
+      FinalOutput = C.getArgs().getLastArg(options::OPT__SLASH_Fo,
+                                           options::OPT__SLASH_Fo_COLON);
+    } else {
+      FinalOutput = C.getArgs().getLastArg(options::OPT_o);
+    }
+
+    if (FinalOutput) {
       return C.addResultFile(FinalOutput->getValue(), &JA);
+    }
   }
 
   // For /P, preprocess to file named after BaseInput.



More information about the cfe-commits mailing list