Skip to content

Commit 411196b

Browse files
authored
[C++20] [Modules] Convert '-fexperimental-modules-reduced-bmi' to '-fmodules-reduced-bmi' (#114382)
According to our previous consensus in https://clang.llvm.org/docs/StandardCPlusPlusModules.html#reduced-bmi, the reduced BMI will be the default and recommend users to use the new option. The `-fexperimental-modules-reduced-bmi ` option is introduced in #85050 in Mar13 and released in 19.x. And now we are in 20's release cycle. Also I rarely receive issue reports about reduced BMI. No matter it is due to the quality of reduced BMI is really good or no one uses it. This patch literally did the second point in https://clang.llvm.org/docs/StandardCPlusPlusModules.html#reduced-bmi
1 parent a295907 commit 411196b

File tree

5 files changed

+53
-17
lines changed

5 files changed

+53
-17
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,10 @@ Modified Compiler Flags
458458
``memset`` and similar functions for which it is a documented undefined
459459
behavior. It is implied by ``-Wnontrivial-memaccess``
460460

461+
- Added ``-fmodules-reduced-bmi`` flag corresponding to
462+
``-fexperimental-modules-reduced-bmi`` flag. The ``-fmodules-reduced-bmi`` flag
463+
is intended to be enabled by default in the future.
464+
461465
Removed Compiler Flags
462466
-------------------------
463467

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/Driver/Options.td

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

3198-
def modules_reduced_bmi : Flag<["-"], "fexperimental-modules-reduced-bmi">,
3198+
def modules_reduced_bmi : Flag<["-"], "fmodules-reduced-bmi">,
31993199
Group<f_Group>, Visibility<[ClangOption, CC1Option]>,
32003200
HelpText<"Generate the reduced BMI">,
32013201
MarshallingInfoFlag<FrontendOpts<"GenReducedBMI">>;
32023202

3203+
def experimental_modules_reduced_bmi : Flag<["-"], "fexperimental-modules-reduced-bmi">,
3204+
Group<f_Group>, Visibility<[ClangOption, CC1Option]>, Alias<modules_reduced_bmi>;
3205+
32033206
def fmodules_embed_all_files : Joined<["-"], "fmodules-embed-all-files">,
32043207
Visibility<[ClangOption, CC1Option, CLOption]>,
32053208
HelpText<"Embed the contents of all files read by this compilation into "

clang/lib/Driver/ToolChains/Clang.cpp

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

42654265
if (Args.hasArg(options::OPT_fmodule_output_EQ))
42664266
Args.AddLastArg(CmdArgs, options::OPT_fmodule_output_EQ);
@@ -4270,7 +4270,7 @@ static bool RenderModulesOptions(Compilation &C, const Driver &D,
42704270
getCXX20NamedModuleOutputPath(Args, Input.getBaseInput())));
42714271
}
42724272

4273-
// Noop if we see '-fexperimental-modules-reduced-bmi' with other translation
4273+
// Noop if we see '-fmodules-reduced-bmi' with other translation
42744274
// units than module units. This is more user friendly to allow end uers to
42754275
// enable this feature without asking for help from build systems.
42764276
Args.ClaimAllArgs(options::OPT_modules_reduced_bmi);

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

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,41 @@
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: -Wno-missing-reduced-bmi -### 2>&1 | FileCheck Hello.cppm -check-prefix=NO_WARN
57+
//
58+
// RUN: %clang -std=c++20 Hello.cppm --precompile -o Hello.pcm \
59+
// RUN: -Wno-missing-reduced-bmi -### 2>&1 | FileCheck Hello.cppm -check-prefix=NO_WARN
3260

3361
//--- Hello.cppm
3462
export module Hello;
3563

3664
// Test that we won't generate the emit-module-interface as 2 phase compilation model.
3765
// CHECK-NOT: -emit-module-interface
38-
// CHECK: "-fexperimental-modules-reduced-bmi"
66+
// CHECK: "-fmodules-reduced-bmi"
3967

4068
// CHECK-UNSPECIFIED: -fmodule-output=Hello.pcm
4169

@@ -46,6 +74,8 @@ export module Hello;
4674
// flag.
4775
// CHECK-EMIT-MODULE-INTERFACE: -emit-module-interface
4876

77+
// NO_WARN-NOT: warning
78+
4979
//--- Hello.cc
5080

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

0 commit comments

Comments
 (0)