[PATCH] D137059: [Driver] [Modules] Introduce -fsave-std-c++-module-file= to specify the path of the module file

Chuanqi Xu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 31 00:55:53 PDT 2022


ChuanqiXu created this revision.
ChuanqiXu added reviewers: dblaikie, ben.boeckel, iains, tschuett.
ChuanqiXu added a project: clang-modules.
Herald added a project: All.
ChuanqiXu requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang.

Successor of D137058 <https://reviews.llvm.org/D137058>. The intention is described as the second step in D137058 <https://reviews.llvm.org/D137058>. This is helpful if the build systems want to generate these output files in other places which is not the same with `-o` specified or the input file lived.


Repository:
  rG LLVM Github Monorepo

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
@@ -8,6 +8,11 @@
 // RUN: mkdir %t/tmp
 // RUN: %clang -std=c++20 %t/Hello.cppm -fsave-std-c++-module-file -c -o %t/tmp/H.o
 // RUN: ls %t/tmp | FileCheck %t/Hello.cppm --check-prefix=CHECK-O
+//
+// RUN: rm -fr %t/tmp/*
+// RUN: %clang -std=c++20 %t/Hello.cppm -fsave-std-c++-module-file=%t/tmp/Hello.pcm \
+// RUN:      -c -o %t/tmp/H.o
+// RUN: ls %t/tmp | FileCheck %t/Hello.cppm --check-prefix=CHECK-EQ
 
 
 //--- Hello.cppm
@@ -15,3 +20,4 @@
 
 // CHECK-DEFAULT: Hello.pcm
 // CHECK-O: H.pcm
+// CHECK-EQ: Hello.pcm
Index: clang/lib/Driver/Driver.cpp
===================================================================
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -5533,18 +5533,24 @@
   }
 
   // If `-fsave-std-c++-module-file` is specfied, then:
-  // - If `-o` is specified, the module file is writing to the same path
+  // - If `-fsave-std-c++-module-file` 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.
   //
   // FIXME: Do we need to handle the case that the calculated output is
   // conflicting with the specified output file or the input file?
   if (!AtTopLevel && isa<PrecompileJobAction>(JA) &&
       JA.getType() == types::TY_ModuleFile &&
-      C.getArgs().hasArg(options::OPT_fsave_std_cxx_module_file)) {
+      (C.getArgs().hasArg(options::OPT_fsave_std_cxx_module_file) ||
+       C.getArgs().hasArg(options::OPT_fsave_std_cxx_module_file_EQ))) {
     SmallString<128> TempPath;
-    if (Arg *FinalOutput = C.getArgs().getLastArg(options::OPT_o))
+
+    if (Arg *ModuleFilePath = C.getArgs().getLastArg(options::OPT_fsave_std_cxx_module_file_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
@@ -2276,6 +2276,8 @@
   PosFlag<SetTrue, [], "Look up implicit modules in the prebuilt module path">,
   NegFlag<SetFalse>, BothFlags<[NoXarchOption, CC1Option]>>;
 
+def fsave_std_cxx_module_file_EQ : Joined<["-"], "fsave-std-c++-module-file=">, Flags<[NoXarchOption, CC1Option]>,
+  HelpText<"Save intermediate module file results when compiling a standard C++ module unit.">;
 def fsave_std_cxx_module_file : Flag<["-"], "fsave-std-c++-module-file">, 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.471914.patch
Type: text/x-patch
Size: 3148 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221031/bc0d4539/attachment-0001.bin>


More information about the cfe-commits mailing list