[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
Sat Feb 8 13:32:09 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 1/2] 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.
>From acad422d098855251252c0c5925f571f1b38631d 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/2] 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 43dbf517485a058..8744745019d15eb 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
More information about the cfe-commits
mailing list