Index: clang/include/clang/Driver/Options.td =================================================================== --- clang/include/clang/Driver/Options.td +++ clang/include/clang/Driver/Options.td @@ -2276,6 +2276,8 @@ PosFlag, NegFlag, 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.">; 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(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/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