Author: Chuanqi Xu Date: 2025-02-28T13:36:29+08:00 New Revision: 170b5736824bd4f70a7bf9dd0028b997d85ba76f
URL: https://github.com/llvm/llvm-project/commit/170b5736824bd4f70a7bf9dd0028b997d85ba76f DIFF: https://github.com/llvm/llvm-project/commit/170b5736824bd4f70a7bf9dd0028b997d85ba76f.diff LOG: [Driver] [C++20] [Modules] Warning for the surprising useless case for reduced BMI Found in downstream. I didn't realize the output file for precompile and reduced BMI refers to the same location. Then the generating process of reduced BMI is basically a waste of time. Added: Modified: clang/include/clang/Basic/DiagnosticDriverKinds.td clang/lib/Driver/ToolChains/Clang.cpp clang/test/Driver/module-fgen-reduced-bmi.cppm Removed: ################################################################################ diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td index 8f532a63f9e04..058fecd4e91ef 100644 --- a/clang/include/clang/Basic/DiagnosticDriverKinds.td +++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td @@ -563,6 +563,11 @@ def err_test_module_file_extension_format : Error< def err_drv_module_output_with_multiple_arch : Error< "option '-fmodule-output' cannot be used with multiple arch options">; +def err_drv_reduced_module_output_overrided : Warning< + "the implicit output of reduced BMI may be overrided by the output file specified by '--precompile'. " + "please consider use '-fmodule-output=' to specify the output file for reduced BMI explicitly">, + InGroup<DiagGroup<"reduced-bmi-output-overrided">>; + def warn_drv_delayed_template_parsing_after_cxx20 : Warning< "-fdelayed-template-parsing is deprecated after C++20">, InGroup<DiagGroup<"delayed-template-parsing-in-cxx20">>; diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 86db3f7678436..4ebbd241d2f0b 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -4250,10 +4250,18 @@ static bool RenderModulesOptions(Compilation &C, const Driver &D, if (Args.hasArg(options::OPT_fmodule_output_EQ)) Args.AddLastArg(CmdArgs, options::OPT_fmodule_output_EQ); - else + else { + if (Args.hasArg(options::OPT__precompile) && + (!Args.hasArg(options::OPT_o) || + Args.getLastArg(options::OPT_o)->getValue() == + getCXX20NamedModuleOutputPath(Args, Input.getBaseInput()))) { + D.Diag(diag::err_drv_reduced_module_output_overrided); + } + CmdArgs.push_back(Args.MakeArgString( "-fmodule-output=" + getCXX20NamedModuleOutputPath(Args, Input.getBaseInput()))); + } } // Noop if we see '-fmodules-reduced-bmi' with other translation diff --git a/clang/test/Driver/module-fgen-reduced-bmi.cppm b/clang/test/Driver/module-fgen-reduced-bmi.cppm index 7329c12941d73..9bdd4c9f6682f 100644 --- a/clang/test/Driver/module-fgen-reduced-bmi.cppm +++ b/clang/test/Driver/module-fgen-reduced-bmi.cppm @@ -48,6 +48,14 @@ // RUN: %clang -std=c++20 Hello.cppm --precompile -fmodules-reduced-bmi \ // RUN: -o Hello.full.pcm -### 2>&1 | FileCheck Hello.cppm \ // RUN: --check-prefix=CHECK-EMIT-MODULE-INTERFACE + +// RUN: %clang -std=c++20 Hello.cppm --precompile -fmodules-reduced-bmi \ +// RUN: -### 2>&1 | FileCheck Hello.cppm \ +// RUN: --check-prefix=CHECK-OVERRIDE-WARN + +// RUN: %clang -std=c++20 Hello.cppm --precompile -fmodules-reduced-bmi \ +// RUN: -o Hello.pcm -### 2>&1 | FileCheck Hello.cppm \ +// RUN: --check-prefix=CHECK-OVERRIDE-WARN // // RUN: %clang -std=c++20 Hello.cc -fmodules-reduced-bmi -Wall -Werror \ // RUN: -c -o Hello.o -### 2>&1 | FileCheck Hello.cc @@ -74,6 +82,8 @@ export module Hello; // flag. // CHECK-EMIT-MODULE-INTERFACE: -emit-module-interface +// CHECK-OVERRIDE-WARN: warning: the implicit output of reduced BMI may be overrided by the output file specified by '--precompile'. {{.*}}-Wreduced-bmi-output-overrided + // NO_WARN-NOT: warning //--- Hello.cc _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits