Skip to content

Commit 7083728

Browse files
committed
[C++20] [Modules] Convert '-fexperimental-modules-reduced-bmi' to '-fmodules-reduced-bmi'
1 parent a6385a3 commit 7083728

File tree

7 files changed

+77
-17
lines changed

7 files changed

+77
-17
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,10 @@ Modified Compiler Flags
393393
``memset`` and similar functions for which it is a documented undefined
394394
behavior.
395395

396+
- Added ``-fmodules-reduced-bmi`` flags corresponding to
397+
``-fexperimental-modules-reduced-bmi`` flag and emit warning for not emitting
398+
reduced BMI.
399+
396400
Removed Compiler Flags
397401
-------------------------
398402

clang/docs/StandardCPlusPlusModules.rst

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -602,16 +602,16 @@ unnecessary dependencies for the BMI. To mitigate the problem, Clang has a
602602
compiler option to reduce the information contained in the BMI. These two
603603
formats are known as Full BMI and Reduced BMI, respectively.
604604

605-
Users can use the ``-fexperimental-modules-reduced-bmi`` option to produce a
605+
Users can use the ``-fmodules-reduced-bmi`` option to produce a
606606
Reduced BMI.
607607

608608
For the one-phase compilation model (CMake implements this model), with
609-
``-fexperimental-modules-reduced-bmi``, the generated BMI will be a Reduced
609+
``-fmodules-reduced-bmi``, the generated BMI will be a Reduced
610610
BMI automatically. (The output path of the BMI is specified by
611611
``-fmodule-output=`` as usual with the one-phase compilation model).
612612

613613
It is also possible to produce a Reduced BMI with the two-phase compilation
614-
model. When ``-fexperimental-modules-reduced-bmi``, ``--precompile``, and
614+
model. When ``-fmodules-reduced-bmi``, ``--precompile``, and
615615
``-fmodule-output=`` are specified, the generated BMI specified by ``-o`` will
616616
be a full BMI and the BMI specified by ``-fmodule-output=`` will be a Reduced
617617
BMI. The dependency graph in this case would look like:
@@ -625,7 +625,7 @@ BMI. The dependency graph in this case would look like:
625625
-> ...
626626
-> consumer_n.cpp
627627
628-
Clang does not emit diagnostics when ``-fexperimental-modules-reduced-bmi`` is
628+
Clang does not emit diagnostics when ``-fmodules-reduced-bmi`` is
629629
used with a non-module unit. This design permits users of the one-phase
630630
compilation model to try using reduced BMIs without needing to modify the build
631631
system. The two-phase compilation module requires build system support.
@@ -691,11 +691,10 @@ ensure it is reachable, e.g. ``using N::g;``.
691691
Support for Reduced BMIs is still experimental, but it may become the default
692692
in the future. The expected roadmap for Reduced BMIs as of Clang 19.x is:
693693

694-
1. ``-fexperimental-modules-reduced-bmi`` is opt-in for 1~2 releases. The period depends
694+
1. ``-fexperimental-modules-reduced-bmi`` was introduced in v19.x
695+
2. For v20.x, ``-fmodules-reduced-bmi`` is introduced as an equivalent non-experimental
696+
option. It is expected to stay opt-in for 1~2 releases, though the period depends
695697
on user feedback and may be extended.
696-
2. Announce that Reduced BMIs are no longer experimental and introduce
697-
``-fmodules-reduced-bmi`` as a new option, and recommend use of the new
698-
option. This transition is expected to take 1~2 additional releases as well.
699698
3. Finally, ``-fmodules-reduced-bmi`` will be the default. When that time
700699
comes, the term BMI will refer to the Reduced BMI and the Full BMI will only
701700
be meaningful to build systems which elect to support two-phase compilation.
@@ -814,8 +813,8 @@ With reduced BMI, non-cascading changes can be more powerful. For example,
814813

815814
.. code-block:: console
816815
817-
$ clang++ -std=c++20 A.cppm -c -fmodule-output=A.pcm -fexperimental-modules-reduced-bmi -o A.o
818-
$ clang++ -std=c++20 B.cppm -c -fmodule-output=B.pcm -fexperimental-modules-reduced-bmi -o B.o -fmodule-file=A=A.pcm
816+
$ clang++ -std=c++20 A.cppm -c -fmodule-output=A.pcm -fmodules-reduced-bmi -o A.o
817+
$ clang++ -std=c++20 B.cppm -c -fmodule-output=B.pcm -fmodules-reduced-bmi -o B.o -fmodule-file=A=A.pcm
819818
$ md5sum B.pcm
820819
6c2bd452ca32ab418bf35cd141b060b9 B.pcm
821820
@@ -831,8 +830,8 @@ and recompile the example:
831830

832831
.. code-block:: console
833832
834-
$ clang++ -std=c++20 A.cppm -c -fmodule-output=A.pcm -fexperimental-modules-reduced-bmi -o A.o
835-
$ clang++ -std=c++20 B.cppm -c -fmodule-output=B.pcm -fexperimental-modules-reduced-bmi -o B.o -fmodule-file=A=A.pcm
833+
$ clang++ -std=c++20 A.cppm -c -fmodule-output=A.pcm -fmodules-reduced-bmi -o A.o
834+
$ clang++ -std=c++20 B.cppm -c -fmodule-output=B.pcm -fmodules-reduced-bmi -o B.o -fmodule-file=A=A.pcm
836835
$ md5sum B.pcm
837836
6c2bd452ca32ab418bf35cd141b060b9 B.pcm
838837

clang/include/clang/Basic/DiagnosticDriverKinds.td

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,13 @@ def err_test_module_file_extension_format : Error<
555555
def err_drv_module_output_with_multiple_arch : Error<
556556
"option '-fmodule-output' can't be used with multiple arch options">;
557557

558+
def warn_drv_module_reduced_bmi_not_enabled : Warning<
559+
"reduced BMI is expected to be enabled by default in Clang 21; it can be enabled "
560+
"explicitly by passing '-fmodules-reduced-bmi' (in one-phase compilation models, "
561+
"like CMake) or by disabling the diagnostic and requesting the build system vendor "
562+
"support reduced BMIs (in two-phase compilation models)">,
563+
InGroup<DiagGroup<"missing-reduced-bmi">>;
564+
558565
def warn_drv_delayed_template_parsing_after_cxx20 : Warning<
559566
"-fdelayed-template-parsing is deprecated after C++20">,
560567
InGroup<DiagGroup<"delayed-template-parsing-in-cxx20">>;

clang/include/clang/Driver/Options.td

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3198,11 +3198,14 @@ defm skip_odr_check_in_gmf : BoolOption<"f", "skip-odr-check-in-gmf",
31983198
"Perform ODR checks for decls in the global module fragment.">>,
31993199
Group<f_Group>;
32003200

3201-
def modules_reduced_bmi : Flag<["-"], "fexperimental-modules-reduced-bmi">,
3201+
def modules_reduced_bmi : Flag<["-"], "fmodules-reduced-bmi">,
32023202
Group<f_Group>, Visibility<[ClangOption, CC1Option]>,
32033203
HelpText<"Generate the reduced BMI">,
32043204
MarshallingInfoFlag<FrontendOpts<"GenReducedBMI">>;
32053205

3206+
def experimental_modules_reduced_bmi : Flag<["-"], "fexperimental-modules-reduced-bmi">,
3207+
Group<f_Group>, Visibility<[ClangOption, CC1Option]>, Alias<modules_reduced_bmi>;
3208+
32063209
def fmodules_embed_all_files : Joined<["-"], "fmodules-embed-all-files">,
32073210
Visibility<[ClangOption, CC1Option, CLOption]>,
32083211
HelpText<"Embed the contents of all files read by this compilation into "

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4257,7 +4257,7 @@ static bool RenderModulesOptions(Compilation &C, const Driver &D,
42574257
if (Args.hasArg(options::OPT_modules_reduced_bmi) &&
42584258
(Input.getType() == driver::types::TY_CXXModule ||
42594259
Input.getType() == driver::types::TY_PP_CXXModule)) {
4260-
CmdArgs.push_back("-fexperimental-modules-reduced-bmi");
4260+
CmdArgs.push_back("-fmodules-reduced-bmi");
42614261

42624262
if (Args.hasArg(options::OPT_fmodule_output_EQ))
42634263
Args.AddLastArg(CmdArgs, options::OPT_fmodule_output_EQ);
@@ -4267,7 +4267,15 @@ static bool RenderModulesOptions(Compilation &C, const Driver &D,
42674267
getCXX20NamedModuleOutputPath(Args, Input.getBaseInput())));
42684268
}
42694269

4270-
// Noop if we see '-fexperimental-modules-reduced-bmi' with other translation
4270+
if ((Input.getType() == driver::types::TY_CXXModule ||
4271+
Input.getType() == driver::types::TY_PP_CXXModule) &&
4272+
(Args.hasArg(options::OPT_fmodule_output) ||
4273+
Args.hasArg(options::OPT_fmodule_output_EQ) ||
4274+
Args.hasArg(options::OPT__precompile)) &&
4275+
!Args.hasArg(options::OPT_modules_reduced_bmi))
4276+
D.Diag(diag::warn_drv_module_reduced_bmi_not_enabled);
4277+
4278+
// Noop if we see '-fmodules-reduced-bmi' with other translation
42714279
// units than module units. This is more user friendly to allow end uers to
42724280
// enable this feature without asking for help from build systems.
42734281
Args.ClaimAllArgs(options::OPT_modules_reduced_bmi);

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

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,47 @@
2929
//
3030
// RUN: %clang -std=c++20 Hello.cc -fexperimental-modules-reduced-bmi -Wall -Werror \
3131
// RUN: -c -o Hello.o -### 2>&1 | FileCheck Hello.cc
32+
//
33+
// RUN: %clang -std=c++20 Hello.cppm -fmodule-output=Hello.pcm \
34+
// RUN: -fmodules-reduced-bmi -c -o Hello.o -### 2>&1 | FileCheck Hello.cppm
35+
//
36+
// RUN: %clang -std=c++20 Hello.cppm \
37+
// RUN: -fmodules-reduced-bmi -c -o Hello.o -### 2>&1 | \
38+
// RUN: FileCheck Hello.cppm --check-prefix=CHECK-UNSPECIFIED
39+
//
40+
// RUN: %clang -std=c++20 Hello.cppm \
41+
// RUN: -fmodules-reduced-bmi -c -### 2>&1 | \
42+
// RUN: FileCheck Hello.cppm --check-prefix=CHECK-NO-O
43+
//
44+
// RUN: %clang -std=c++20 Hello.cppm \
45+
// RUN: -fmodules-reduced-bmi -c -o AnotherName.o -### 2>&1 | \
46+
// RUN: FileCheck Hello.cppm --check-prefix=CHECK-ANOTHER-NAME
47+
//
48+
// RUN: %clang -std=c++20 Hello.cppm --precompile -fmodules-reduced-bmi \
49+
// RUN: -o Hello.full.pcm -### 2>&1 | FileCheck Hello.cppm \
50+
// RUN: --check-prefix=CHECK-EMIT-MODULE-INTERFACE
51+
//
52+
// RUN: %clang -std=c++20 Hello.cc -fmodules-reduced-bmi -Wall -Werror \
53+
// RUN: -c -o Hello.o -### 2>&1 | FileCheck Hello.cc
54+
//
55+
// RUN: %clang -std=c++20 Hello.cppm -fmodule-output=Hello.pcm -c -o Hello.o \
56+
// RUN: -### 2>&1 | FileCheck Hello.cppm -check-prefix=WARN
57+
//
58+
// RUN: %clang -std=c++20 Hello.cppm --precompile -o Hello.pcm \
59+
// RUN: -### 2>&1 | FileCheck Hello.cppm -check-prefix=WARN
60+
//
61+
// RUN: %clang -std=c++20 Hello.cppm -fmodule-output=Hello.pcm -c -o Hello.o \
62+
// RUN: -Wno-missing-reduced-bmi -### 2>&1 | FileCheck Hello.cppm -check-prefix=NO_WARN
63+
//
64+
// RUN: %clang -std=c++20 Hello.cppm --precompile -o Hello.pcm \
65+
// RUN: -Wno-missing-reduced-bmi -### 2>&1 | FileCheck Hello.cppm -check-prefix=NO_WARN
3266

3367
//--- Hello.cppm
3468
export module Hello;
3569

3670
// Test that we won't generate the emit-module-interface as 2 phase compilation model.
3771
// CHECK-NOT: -emit-module-interface
38-
// CHECK: "-fexperimental-modules-reduced-bmi"
72+
// CHECK: "-fmodules-reduced-bmi"
3973

4074
// CHECK-UNSPECIFIED: -fmodule-output=Hello.pcm
4175

@@ -46,6 +80,9 @@ export module Hello;
4680
// flag.
4781
// CHECK-EMIT-MODULE-INTERFACE: -emit-module-interface
4882

83+
// WARN: reduced BMI is expected to be enabled by default in Clang 21;
84+
// NO_WARN-NOT: warning
85+
4986
//--- Hello.cc
5087

51-
// CHECK-NOT: "-fexperimental-modules-reduced-bmi"
88+
// CHECK-NOT: "-fmodules-reduced-bmi"

libcxx/utils/libcxx/test/format.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ def parseScript(test, preamble):
172172
f"{compileFlags} "
173173
"-Wno-reserved-module-identifier -Wno-reserved-user-defined-literal "
174174
"-fmodule-file=std=%T/std.pcm " # The std.compat module imports std.
175+
"-fmodules-reduced-bmi "
175176
"--precompile -o %T/std.compat.pcm -c %{module-dir}/std.compat.cppm",
176177
)
177178
moduleCompileFlags.extend(
@@ -188,6 +189,7 @@ def parseScript(test, preamble):
188189
"%dbg(MODULE std) %{cxx} %{flags} "
189190
f"{compileFlags} "
190191
"-Wno-reserved-module-identifier -Wno-reserved-user-defined-literal "
192+
"-fmodules-reduced-bmi "
191193
"--precompile -o %T/std.pcm -c %{module-dir}/std.cppm",
192194
)
193195
moduleCompileFlags.extend(["-fmodule-file=std=%T/std.pcm", "%T/std.pcm"])

0 commit comments

Comments
 (0)