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

>From 3a84b5906330c4f6308e10c50381f06956c27e2d Mon Sep 17 00:00:00 2001
From: Sharadh Rajaraman <r.shar...@outlook.sg>
Date: Tue, 24 Dec 2024 09:32:21 +0000
Subject: [PATCH 1/6] Accept /Fo and -Fo in `-fmodule-output` when running
 under CL mode

---
 clang/lib/Driver/Driver.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 4d9492ea08f6479..67b5e7268051aea 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -6099,7 +6099,7 @@ 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))
+    if (Arg *FinalOutput = C.getArgs().getLastArg(options::OPT_o, 
options::OPT__SLASH_Fo, options::OPT__SLASH_Fo_COLON))
       return C.addResultFile(FinalOutput->getValue(), &JA);
   }
 

>From 1a471fe6ef2549c53b393ac407756f4a4bbc7363 Mon Sep 17 00:00:00 2001
From: Sharadh Rajaraman <r.shar...@outlook.sg>
Date: Sun, 5 Jan 2025 14:09:24 +0000
Subject: [PATCH 2/6] Use `IsCLMode` to guard cl-style output argument presence

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

diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 67b5e7268051aea..41c30899807c528 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -6099,8 +6099,15 @@ 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, 
options::OPT__SLASH_Fo, options::OPT__SLASH_Fo_COLON))
+    Arg *FinalOutput =
+        IsCLMode()
+            ? C.getArgs().getLastArg(options::OPT_o, options::OPT__SLASH_Fo,
+                                     options::OPT__SLASH_Fo_COLON)
+            : C.getArgs().getLastArg(options::OPT_o);
+
+    if (FinalOutput != nullptr) {
       return C.addResultFile(FinalOutput->getValue(), &JA);
+    }
   }
 
   // For /P, preprocess to file named after BaseInput.

>From fe69cf4b4de805b67b877e7b30165e32a986dedc Mon Sep 17 00:00:00 2001
From: Sharadh Rajaraman <r.shar...@outlook.sg>
Date: Thu, 9 Jan 2025 19:20:30 +0000
Subject: [PATCH 3/6] Test for `/Yc` and `/Fp` under CL mode

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

diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 41c30899807c528..32d87a4eaa59ca6 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -6100,7 +6100,9 @@ const char *Driver::GetNamedOutputPath(Compilation &C, 
const JobAction &JA,
   // Output to a user requested destination?
   if (AtTopLevel && !isa<DsymutilJobAction>(JA) && !isa<VerifyJobAction>(JA)) {
     Arg *FinalOutput =
-        IsCLMode()
+        // CL and not generating a PCH: test for Fo, Fp, and Yc
+        IsCLMode() && !(C.getArgs().hasArg(options::OPT__SLASH_Yc) &&
+                        C.getArgs().hasArg(options::OPT__SLASH_Fp))
             ? C.getArgs().getLastArg(options::OPT_o, options::OPT__SLASH_Fo,
                                      options::OPT__SLASH_Fo_COLON)
             : C.getArgs().getLastArg(options::OPT_o);

>From d7b7e93fb04fc624e7ce3758bd385bdea1a388a9 Mon Sep 17 00:00:00 2001
From: Sharadh Rajaraman <r.shar...@outlook.sg>
Date: Sun, 12 Jan 2025 21:44:33 +0000
Subject: [PATCH 4/6] Account for /Yc when generating PCH

---
 clang/lib/Driver/Driver.cpp | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 32d87a4eaa59ca6..a59f7108c076029 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -6099,11 +6099,11 @@ 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)) {
+    // CL and not building a PCH. Not sure why the GNU-style driver doesn't 
need
+    // this. May need to rethink.
     Arg *FinalOutput =
-        // CL and not generating a PCH: test for Fo, Fp, and Yc
-        IsCLMode() && !(C.getArgs().hasArg(options::OPT__SLASH_Yc) &&
-                        C.getArgs().hasArg(options::OPT__SLASH_Fp))
-            ? C.getArgs().getLastArg(options::OPT_o, options::OPT__SLASH_Fo,
+        IsCLMode() && !C.getArgs().hasArg(options::OPT__SLASH_Yc)
+            ? C.getArgs().getLastArg(options::OPT__SLASH_Fo,
                                      options::OPT__SLASH_Fo_COLON)
             : C.getArgs().getLastArg(options::OPT_o);
 

>From 1f40c12decf6faef58dc4e268dd3aac0c3c1874a Mon Sep 17 00:00:00 2001
From: Sharadh Rajaraman <r.shar...@outlook.sg>
Date: Sun, 12 Jan 2025 23:51:16 +0000
Subject: [PATCH 5/6] Fix PCH and cl-output tests

---
 clang/lib/Driver/Driver.cpp | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index a59f7108c076029..18a3fee12d7024e 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -6099,15 +6099,13 @@ 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)) {
-    // CL and not building a PCH. Not sure why the GNU-style driver doesn't 
need
-    // this. May need to rethink.
     Arg *FinalOutput =
-        IsCLMode() && !C.getArgs().hasArg(options::OPT__SLASH_Yc)
+        IsCLMode() && !C.getArgs().hasArg(options::OPT__SLASH_Yc) &&
+                (isa<PreprocessJobAction>(JA) || isa<PrecompileJobAction>(JA))
             ? C.getArgs().getLastArg(options::OPT__SLASH_Fo,
                                      options::OPT__SLASH_Fo_COLON)
             : C.getArgs().getLastArg(options::OPT_o);
-
-    if (FinalOutput != nullptr) {
+    if (FinalOutput) {
       return C.addResultFile(FinalOutput->getValue(), &JA);
     }
   }

>From ac8652993e3e950e0ec7e8f51f0453cfa7e21c3e Mon Sep 17 00:00:00 2001
From: Sharadh Rajaraman <shar...@petagene.com>
Date: Fri, 7 Feb 2025 21:02:21 +0000
Subject: [PATCH 6/6] Fix target-filename.cpp test with an argument check

---
 clang/lib/Driver/Driver.cpp | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 18a3fee12d7024e..98923b69b0e00ec 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -6097,14 +6097,24 @@ 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)) {
-    Arg *FinalOutput =
-        IsCLMode() && !C.getArgs().hasArg(options::OPT__SLASH_Yc) &&
-                (isa<PreprocessJobAction>(JA) || isa<PrecompileJobAction>(JA))
-            ? C.getArgs().getLastArg(options::OPT__SLASH_Fo,
-                                     options::OPT__SLASH_Fo_COLON)
-            : 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);
     }

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to