[PATCH] D137059: [Driver] [C++20] [Modules] Support -fmodule-output= (2/2)

Chuanqi Xu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 14 19:52:55 PST 2022


ChuanqiXu updated this revision to Diff 483075.
ChuanqiXu added a comment.

Update since the dependent one changes.


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/module-output.cppm


Index: clang/test/Driver/module-output.cppm
===================================================================
--- clang/test/Driver/module-output.cppm
+++ clang/test/Driver/module-output.cppm
@@ -2,8 +2,14 @@
 // output and the name of the .pcm file should be the same with the output file.
 // RUN: %clang -std=c++20 %s -fmodule-output -c -o %t/output/Hello.o \
 // RUN:   -### 2>&1 | FileCheck %s
+//
+// Tests that the .pcm file will be generated in the same path with the specified one in the comamnd line.
+// RUN: %clang -std=c++20 %s -fmodule-output=%t/pcm/Hello.pcm -o %t/Hello.o \
+// RUN:   -c -### 2>&1 | FileCheck %s --check-prefix=CHECK-SPECIFIED
 
 export module Hello;
 
 // CHECK: "-emit-module-interface" {{.*}}"-main-file-name" "module-output.cppm" {{.*}}"-o" "{{.*}}/Hello.pcm" "-x" "c++" "{{.*}}/module-output.cppm"
 // CHECK: "-emit-obj" {{.*}}"-main-file-name" "module-output.cppm" {{.*}}"-o" "{{.*}}/Hello.o" "-x" "pcm" "{{.*}}/Hello.pcm"
+// CHECK-SPECIFIED: "-emit-module-interface" {{.*}}"-main-file-name" "module-output.cppm" {{.*}}"-o" "{{.*}}/Hello.pcm" "-x" "c++" "{{.*}}/module-output.cppm"
+// CHECK-SPECIFIED: "-emit-obj" {{.*}}"-main-file-name" "module-output.cppm" {{.*}}"-o" "{{.*}}/Hello.o" "-x" "pcm" "{{.*}}/Hello.pcm"
Index: clang/lib/Driver/Driver.cpp
===================================================================
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -5541,6 +5541,8 @@
   }
 
   // If `-fmodule-output` is specfied, then:
+  // - If `-fmodule-output` has a value, the module file is
+  //   writing to the value.
   // - If `-o` is specified, the module file is written to the same path
   //   with the output filename in module file's suffix. 
   // - If `-o` is not specified, the module file is written to the working
@@ -5548,10 +5550,14 @@
   //   falls out to reuse the logic to compute the path of the object files.
   if (!AtTopLevel && isa<PrecompileJobAction>(JA) &&
       JA.getType() == types::TY_ModuleFile &&
-      C.getArgs().hasArg(options::OPT_fmodule_output) &&
-      C.getArgs().hasArg(options::OPT_o)) {
+      (C.getArgs().hasArg(options::OPT_fmodule_output) &&
+       C.getArgs().hasArg(options::OPT_o)) ||
+      C.getArgs().hasArg(options::OPT_fmodule_output_EQ)) {
     SmallString<128> TempPath;
-    TempPath = C.getArgs().getLastArg(options::OPT_o)->getValue();
+    if (Arg *ModuleFilePath = C.getArgs().getLastArg(options::OPT_fmodule_output_EQ))
+      TempPath = ModuleFilePath->getValue();
+    else
+      TempPath = C.getArgs().getLastArg(options::OPT_o)->getValue();
     const char *Extension = types::getTypeTempSuffix(JA.getType());
     llvm::sys::path::replace_extension(TempPath, Extension);
     return C.addResultFile(C.getArgs().MakeArgString(TempPath.c_str()), &JA);
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.483075.patch
Type: text/x-patch
Size: 3540 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221215/2431bff0/attachment.bin>


More information about the cfe-commits mailing list