[PATCH] D137059: [Driver] [C++20] [Modules] Support -fmodule-output= (2/2)
Chuanqi Xu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Dec 8 19:32:05 PST 2022
ChuanqiXu updated this revision to Diff 481504.
ChuanqiXu retitled this revision from "[Driver] [Modules] Introduce -fsave-std-c++-module-file= to specify the path of the module file (2/2)" to "[Driver] [C++20] [Modules] Support -fmodule-output= (2/2)".
ChuanqiXu added a comment.
Rename the option to `-fmodule-output` according to the discussion from https://gcc.gnu.org/pipermail/gcc/2022-December/240239.html
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D137059/new/
https://reviews.llvm.org/D137059
Files:
clang/include/clang/Driver/Options.td
clang/lib/Driver/Driver.cpp
clang/test/Driver/save-std-c++-module-file.cpp
Index: clang/test/Driver/save-std-c++-module-file.cpp
===================================================================
--- clang/test/Driver/save-std-c++-module-file.cpp
+++ clang/test/Driver/save-std-c++-module-file.cpp
@@ -7,9 +7,16 @@
//
// RUN: %clang -std=c++20 %t/Hello.cppm -fmodule-output -o %t/output/Hello.o \
// RUN: -### 2>&1 | FileCheck %t/Hello.cppm -DPREFIX=%t --check-prefix=CHECK-WITH-OUTPUT
+//
+// RUN: %clang -std=c++20 %t/Hello.cppm -fmodule-output=%t/tmp/H.pcm \
+// RUN: -### 2>&1 | FileCheck %t/Hello.cppm -DPREFIX=%t --check-prefix=CHECK-SPECIFIED
+//
+// RUN: %clang -std=c++20 %t/Hello.cppm -fmodule-output=%t/tmp/H.pcm -o %t/Hello.o \
+// RUN: -### 2>&1 | FileCheck %t/Hello.cppm -DPREFIX=%t --check-prefix=CHECK-SPECIFIED
//--- Hello.cppm
export module Hello;
// CHECK: "-o" "[[PREFIX]]/Hello.pcm"
// CHECK-WITH-OUTPUT: "-o" "[[PREFIX]]/output/Hello.pcm"
+// CHECK-SPECIFIED: "-o" "[[PREFIX]]/tmp/H.pcm"
Index: clang/lib/Driver/Driver.cpp
===================================================================
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -5530,15 +5530,21 @@
}
// If `-fmodule-output` is specfied, then:
- // - If `-o` is specified, the module file is writing to the same path
+ // - If `-fmodule-output` has a value, the module file is
+ // writing to the value.
+ // - Else if `-o` is specified, the module file is writing to the same path
// with the output file in module file's suffix.
- // - If `-o` is not specified, the module file is writing to the same path
+ // - Else, the module file is writing to the same path
// with the input file in module file's suffix.
if (!AtTopLevel && isa<PrecompileJobAction>(JA) &&
JA.getType() == types::TY_ModuleFile &&
- C.getArgs().hasArg(options::OPT_fmodule_output)) {
+ (C.getArgs().hasArg(options::OPT_fmodule_output) ||
+ C.getArgs().hasArg(options::OPT_fmodule_output_EQ))) {
SmallString<128> TempPath;
- if (Arg *FinalOutput = C.getArgs().getLastArg(options::OPT_o))
+
+ if (Arg *ModuleFilePath = C.getArgs().getLastArg(options::OPT_fmodule_output_EQ))
+ TempPath = ModuleFilePath->getValue();
+ else if (Arg *FinalOutput = C.getArgs().getLastArg(options::OPT_o))
TempPath = FinalOutput->getValue();
else
TempPath = BaseInput;
Index: clang/include/clang/Driver/Options.td
===================================================================
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -2285,6 +2285,8 @@
PosFlag<SetTrue, [], "Look up implicit modules in the prebuilt module path">,
NegFlag<SetFalse>, BothFlags<[NoXarchOption, CC1Option]>>;
+def fmodule_output_EQ : Joined<["-"], "fmodule-output=">, Flags<[NoXarchOption, CC1Option]>,
+ HelpText<"Save intermediate module file results when compiling a standard C++ module unit.">;
def fmodule_output : Flag<["-"], "fmodule-output">, Flags<[NoXarchOption, CC1Option]>,
HelpText<"Save intermediate module file results when compiling a standard C++ module unit.">;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137059.481504.patch
Type: text/x-patch
Size: 3098 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221209/239c4237/attachment.bin>
More information about the cfe-commits
mailing list