ChuanqiXu updated this revision to Diff 481978. ChuanqiXu added a comment. Update after D137058 <https://reviews.llvm.org/D137058> updated.
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 @@ -7,6 +7,15 @@ // 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 -DOUTPUT_PATH=%t/output --check-prefix=CHECK-WITH-OUTPUT +// +// 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 \ +// RUN: -c -### 2>&1 | FileCheck %s -DPCM_PATH=%t/pcm --check-prefix=CHECK-SPECIFIED +// +// Tests that the .pcm file will be generated in the same path with the specified one in the comamnd line +// even if we specified the output file. +// RUN: %clang -std=c++20 %s -fmodule-output=%t/pcm/Hello.pcm -o %t/Hello.o \ +// RUN: -c -### 2>&1 | FileCheck %s -DPCM_PATH=%t/pcm --check-prefix=CHECK-SPECIFIED-WITH-OUTPUT export module Hello; @@ -14,3 +23,7 @@ // CHECK: "-emit-obj" {{.*}}"-main-file-name" "module-output.cppm" {{.*}}"-o" "module-output.o" "-x" "pcm" "[[SOURCE_PATH]]/module-output.pcm" // CHECK-WITH-OUTPUT: "-emit-module-interface" {{.*}}"-main-file-name" "module-output.cppm" {{.*}}"-o" "[[OUTPUT_PATH]]/Hello.pcm" "-x" "c++" "{{.*}}/module-output.cppm" // CHECK-WITH-OUTPUT: "-emit-obj" {{.*}}"-main-file-name" "module-output.cppm" {{.*}}"-o" "[[OUTPUT_PATH]]/Hello.o" "-x" "pcm" "[[OUTPUT_PATH]]/Hello.pcm" +// CHECK-SPECIFIED: "-emit-module-interface" {{.*}}"-main-file-name" "module-output.cppm" {{.*}}"-o" "[[PCM_PATH]]/Hello.pcm" "-x" "c++" "{{.*}}/module-output.cppm" +// CHECK-SPECIFIED: "-emit-obj" {{.*}}"-main-file-name" "module-output.cppm" {{.*}}"-o" "module-output.o" "-x" "pcm" "[[PCM_PATH]]/Hello.pcm" +// CHECK-SPECIFIED-WITH-OUTPUT: "-emit-module-interface" {{.*}}"-main-file-name" "module-output.cppm" {{.*}}"-o" "[[PCM_PATH]]/Hello.pcm" "-x" "c++" "{{.*}}/module-output.cppm" +// CHECK-SPECIFIED-WITH-OUTPUT: "-emit-obj" {{.*}}"-main-file-name" "module-output.cppm" {{.*}}"-o" "{{.*}}/Hello.o" "-x" "pcm" "[[PCM_PATH]]/Hello.pcm" 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<PrecompileJobAction>(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/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.">;
Index: clang/test/Driver/module-output.cppm =================================================================== --- clang/test/Driver/module-output.cppm +++ clang/test/Driver/module-output.cppm @@ -7,6 +7,15 @@ // 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 -DOUTPUT_PATH=%t/output --check-prefix=CHECK-WITH-OUTPUT +// +// 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 \ +// RUN: -c -### 2>&1 | FileCheck %s -DPCM_PATH=%t/pcm --check-prefix=CHECK-SPECIFIED +// +// Tests that the .pcm file will be generated in the same path with the specified one in the comamnd line +// even if we specified the output file. +// RUN: %clang -std=c++20 %s -fmodule-output=%t/pcm/Hello.pcm -o %t/Hello.o \ +// RUN: -c -### 2>&1 | FileCheck %s -DPCM_PATH=%t/pcm --check-prefix=CHECK-SPECIFIED-WITH-OUTPUT export module Hello; @@ -14,3 +23,7 @@ // CHECK: "-emit-obj" {{.*}}"-main-file-name" "module-output.cppm" {{.*}}"-o" "module-output.o" "-x" "pcm" "[[SOURCE_PATH]]/module-output.pcm" // CHECK-WITH-OUTPUT: "-emit-module-interface" {{.*}}"-main-file-name" "module-output.cppm" {{.*}}"-o" "[[OUTPUT_PATH]]/Hello.pcm" "-x" "c++" "{{.*}}/module-output.cppm" // CHECK-WITH-OUTPUT: "-emit-obj" {{.*}}"-main-file-name" "module-output.cppm" {{.*}}"-o" "[[OUTPUT_PATH]]/Hello.o" "-x" "pcm" "[[OUTPUT_PATH]]/Hello.pcm" +// CHECK-SPECIFIED: "-emit-module-interface" {{.*}}"-main-file-name" "module-output.cppm" {{.*}}"-o" "[[PCM_PATH]]/Hello.pcm" "-x" "c++" "{{.*}}/module-output.cppm" +// CHECK-SPECIFIED: "-emit-obj" {{.*}}"-main-file-name" "module-output.cppm" {{.*}}"-o" "module-output.o" "-x" "pcm" "[[PCM_PATH]]/Hello.pcm" +// CHECK-SPECIFIED-WITH-OUTPUT: "-emit-module-interface" {{.*}}"-main-file-name" "module-output.cppm" {{.*}}"-o" "[[PCM_PATH]]/Hello.pcm" "-x" "c++" "{{.*}}/module-output.cppm" +// CHECK-SPECIFIED-WITH-OUTPUT: "-emit-obj" {{.*}}"-main-file-name" "module-output.cppm" {{.*}}"-o" "{{.*}}/Hello.o" "-x" "pcm" "[[PCM_PATH]]/Hello.pcm" 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<PrecompileJobAction>(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/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.">;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits