Skip to content

Commit 170b573

Browse files
committed
[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.
1 parent 3cccb20 commit 170b573

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

clang/include/clang/Basic/DiagnosticDriverKinds.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,11 @@ def err_test_module_file_extension_format : Error<
563563
def err_drv_module_output_with_multiple_arch : Error<
564564
"option '-fmodule-output' cannot be used with multiple arch options">;
565565

566+
def err_drv_reduced_module_output_overrided : Warning<
567+
"the implicit output of reduced BMI may be overrided by the output file specified by '--precompile'. "
568+
"please consider use '-fmodule-output=' to specify the output file for reduced BMI explicitly">,
569+
InGroup<DiagGroup<"reduced-bmi-output-overrided">>;
570+
566571
def warn_drv_delayed_template_parsing_after_cxx20 : Warning<
567572
"-fdelayed-template-parsing is deprecated after C++20">,
568573
InGroup<DiagGroup<"delayed-template-parsing-in-cxx20">>;

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4250,10 +4250,18 @@ static bool RenderModulesOptions(Compilation &C, const Driver &D,
42504250

42514251
if (Args.hasArg(options::OPT_fmodule_output_EQ))
42524252
Args.AddLastArg(CmdArgs, options::OPT_fmodule_output_EQ);
4253-
else
4253+
else {
4254+
if (Args.hasArg(options::OPT__precompile) &&
4255+
(!Args.hasArg(options::OPT_o) ||
4256+
Args.getLastArg(options::OPT_o)->getValue() ==
4257+
getCXX20NamedModuleOutputPath(Args, Input.getBaseInput()))) {
4258+
D.Diag(diag::err_drv_reduced_module_output_overrided);
4259+
}
4260+
42544261
CmdArgs.push_back(Args.MakeArgString(
42554262
"-fmodule-output=" +
42564263
getCXX20NamedModuleOutputPath(Args, Input.getBaseInput())));
4264+
}
42574265
}
42584266

42594267
// Noop if we see '-fmodules-reduced-bmi' with other translation

clang/test/Driver/module-fgen-reduced-bmi.cppm

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@
4848
// RUN: %clang -std=c++20 Hello.cppm --precompile -fmodules-reduced-bmi \
4949
// RUN: -o Hello.full.pcm -### 2>&1 | FileCheck Hello.cppm \
5050
// RUN: --check-prefix=CHECK-EMIT-MODULE-INTERFACE
51+
52+
// RUN: %clang -std=c++20 Hello.cppm --precompile -fmodules-reduced-bmi \
53+
// RUN: -### 2>&1 | FileCheck Hello.cppm \
54+
// RUN: --check-prefix=CHECK-OVERRIDE-WARN
55+
56+
// RUN: %clang -std=c++20 Hello.cppm --precompile -fmodules-reduced-bmi \
57+
// RUN: -o Hello.pcm -### 2>&1 | FileCheck Hello.cppm \
58+
// RUN: --check-prefix=CHECK-OVERRIDE-WARN
5159
//
5260
// RUN: %clang -std=c++20 Hello.cc -fmodules-reduced-bmi -Wall -Werror \
5361
// RUN: -c -o Hello.o -### 2>&1 | FileCheck Hello.cc
@@ -74,6 +82,8 @@ export module Hello;
7482
// flag.
7583
// CHECK-EMIT-MODULE-INTERFACE: -emit-module-interface
7684

85+
// CHECK-OVERRIDE-WARN: warning: the implicit output of reduced BMI may be overrided by the output file specified by '--precompile'. {{.*}}-Wreduced-bmi-output-overrided
86+
7787
// NO_WARN-NOT: warning
7888

7989
//--- Hello.cc

0 commit comments

Comments
 (0)