[clang] Accept `cl`-style output arguments (`/Fo`, `-Fo`) for `--fmodule-output` (PR #121046)
Sharadh Rajaraman via cfe-commits
cfe-commits at lists.llvm.org
Sun Jan 12 13:45:05 PST 2025
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.sharadh at outlook.sg>
Date: Tue, 24 Dec 2024 09:32:21 +0000
Subject: [PATCH 1/4] 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 4d9492ea08f647..67b5e7268051ae 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.sharadh at outlook.sg>
Date: Sun, 5 Jan 2025 14:09:24 +0000
Subject: [PATCH 2/4] 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 67b5e7268051ae..41c30899807c52 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.sharadh at outlook.sg>
Date: Thu, 9 Jan 2025 19:20:30 +0000
Subject: [PATCH 3/4] 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 41c30899807c52..32d87a4eaa59ca 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 ff22639d751a38e633a5b2e4fe42586d81b36499 Mon Sep 17 00:00:00 2001
From: Sharadh Rajaraman <r.sharadh at outlook.sg>
Date: Sun, 12 Jan 2025 21:44:33 +0000
Subject: [PATCH 4/4] Account for /Yc when generating PCH
---
clang/lib/Driver/Driver.cpp | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 32d87a4eaa59ca..1bab4efc75db17 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -6099,12 +6099,10 @@ 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 =
- // 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)
+ // 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)
+ ? C.getArgs().getLastArg(options::OPT__SLASH_Fo, options::OPT__SLASH_Fo_COLON)
: C.getArgs().getLastArg(options::OPT_o);
if (FinalOutput != nullptr) {
More information about the cfe-commits
mailing list