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