[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
Mon Feb 10 12:03:23 PST 2025


================
@@ -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);
+    }
----------------
sharadhr wrote:

I've updated the OP message with the reasoning for this. This logic in particular is to resolve `lit` test cases that failed when `/Yp` was passed to `clang-cl.exe`, i.e. PCHs were generated. I believe this is because `/Yp` uses `/Fo` for the PCH output, and therefore this invocation needs to use `/o` (or `-o`). 

`HasAnyOutputArg` was written _specifically_ to resolve `llvm-project\clang\test\ClangScanDeps\target-filename.cpp` failing. It feels like a weird hack and I'm open to suggestions.

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


More information about the cfe-commits mailing list