[clang] [clang-cl] Accept `cl`-style output arguments (`/Fo`, `-Fo`) for `--precompile` (PR #121046)
Sharadh Rajaraman via cfe-commits
cfe-commits at lists.llvm.org
Thu May 15 03:43:01 PDT 2025
https://github.com/sharadhr updated https://github.com/llvm/llvm-project/pull/121046
>From d6c2b9b7ef542975d9313dacd10003a9a6629504 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 1/3] 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 90d8e823d1d02..4aefa7196354d 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -6204,10 +6204,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.
>From 59dcf4d9c9218bfbf6da3b7a3b99c055707d477b Mon Sep 17 00:00:00 2001
From: Sharadh Rajaraman <r.sharadh at outlook.sg>
Date: Sat, 8 Feb 2025 21:24:53 +0000
Subject: [PATCH 2/3] Add a test for the -fmodule-output BMI output file
---
clang/test/Driver/cl-cxx20-modules.cppm | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/clang/test/Driver/cl-cxx20-modules.cppm b/clang/test/Driver/cl-cxx20-modules.cppm
index 43dbf517485a0..8744745019d15 100644
--- a/clang/test/Driver/cl-cxx20-modules.cppm
+++ b/clang/test/Driver/cl-cxx20-modules.cppm
@@ -14,3 +14,11 @@
//--- test.pcm
// CPP20WARNING-NOT: clang-cl: warning: argument unused during compilation: '/std:c++20' [-Wunused-command-line-argument]
+
+// test whether the following outputs %Hello.bmi
+// RUN: %clang_cl /std:c++20 --precompile -x c++-module -fmodule-output=%t/Hello.bmi -Fo"%t/Hello.bmi" -c %t/Hello.cppm -### 2>&1 | FileCheck %s
+// CHECK: "-emit-module-interface"
+// CHECK: "-o" "{{.*}}Hello.bmi"
+
+//--- Hello.cppm
+export module Hello;
\ No newline at end of file
>From 865385588ed11ced81b3fd741d1840b7df431c22 Mon Sep 17 00:00:00 2001
From: Sharadh Rajaraman <r.sharadh at outlook.sg>
Date: Thu, 15 May 2025 10:44:52 +0800
Subject: [PATCH 3/3] SLASH_Fo and SLASH_Fo_COLON are aliases
---
clang/lib/Driver/Driver.cpp | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 4aefa7196354d..45e728e8f22bf 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -6211,15 +6211,14 @@ const char *Driver::GetNamedOutputPath(Compilation &C, const JobAction &JA,
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);
+ options::OPT_o, options::OPT__SLASH_Fo);
Arg *FinalOutput = nullptr;
if (IsCLNonPCH && HasAnyOutputArg) {
FinalOutput = C.getArgs().getLastArg(
- options::OPT_o, options::OPT__SLASH_Fo, options::OPT__SLASH_Fo_COLON);
+ options::OPT_o, options::OPT__SLASH_Fo);
} else if (IsCLNonPCH) {
- FinalOutput = C.getArgs().getLastArg(options::OPT__SLASH_Fo,
- options::OPT__SLASH_Fo_COLON);
+ FinalOutput = C.getArgs().getLastArg(options::OPT__SLASH_Fo);
} else {
FinalOutput = C.getArgs().getLastArg(options::OPT_o);
}
More information about the cfe-commits
mailing list