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

Chuanqi Xu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Dec 16 00:31:32 PST 2022


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

Update since the dependent one changed.


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
@@ -11,12 +11,19 @@
 // specified multiple input files.
 // RUN: %clang -std=c++20 %t/Hello.cppm %t/AnotherModule.cppm -fmodule-output -o \
 // RUN:   %t/output/a.out -### 2>&1 | FileCheck  %t/AnotherModule.cppm
+//
+// 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 %t/Hello.cppm -fmodule-output=%t/pcm/Hello.pcm -o %t/Hello.o \
+// RUN:   -c -### 2>&1 | FileCheck %t/Hello.cppm --check-prefix=CHECK-SPECIFIED
 
 //--- Hello.cppm
 export module Hello;
 
 // CHECK: "-emit-module-interface" {{.*}}"-main-file-name" "Hello.cppm" {{.*}}"-o" "{{.*}}/output/Hello.pcm" "-x" "c++" "{{.*}}/Hello.cppm"
 // CHECK: "-emit-obj" {{.*}}"-main-file-name" "Hello.cppm" {{.*}}"-o" "{{.*}}/output/Hello.o" "-x" "pcm" "{{.*}}/output/Hello.pcm"
+// CHECK-SPECIFIED: "-emit-module-interface" {{.*}}"-main-file-name" "Hello.cppm" {{.*}}"-o" "{{.*}}/Hello.pcm" "-x" "c++" "{{.*}}/Hello.cppm"
+// CHECK-SPECIFIED: "-emit-obj" {{.*}}"-main-file-name" "Hello.cppm" {{.*}}"-o" "{{.*}}/Hello.o" "-x" "pcm" "{{.*}}/Hello.pcm"
 
 //--- AnotherModule.cppm
 export module AnotherModule;
Index: clang/lib/Driver/Driver.cpp
===================================================================
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -5540,6 +5540,19 @@
     return "-";
   }
 
+  // If `-fmodule-output=` is specfied, then the module file is
+  //   writing to the value.
+  if (!AtTopLevel && isa<PrecompileJobAction>(JA) &&
+      JA.getType() == types::TY_ModuleFile &&
+      C.getArgs().hasArg(options::OPT_fmodule_output_EQ)) {
+    SmallString<128> TempPath;
+    TempPath =
+      C.getArgs().getLastArg(options::OPT_fmodule_output_EQ)->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);
+  }
+
   if (IsDXCMode() && !C.getArgs().hasArg(options::OPT_o))
     return "-";
 
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.483449.patch
Type: text/x-patch
Size: 2971 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221216/a86465b8/attachment.bin>


More information about the cfe-commits mailing list