c++ modules: enum TYPE_MIN/MAX_VALUE streaming [PR106848]
authorPatrick Palka <ppalka@redhat.com>
Tue, 25 Oct 2022 17:41:18 +0000 (13:41 -0400)
committerPatrick Palka <ppalka@redhat.com>
Tue, 25 Oct 2022 17:41:18 +0000 (13:41 -0400)
commit15d67c11ac0479b08e3badcafdee7e0a6f062349
treed13224fca8b299e96dec21b732930074cab1ad26
parent1c64aba8cdf6509533f554ad86640f274cdbe37f
c++ modules: enum TYPE_MIN/MAX_VALUE streaming [PR106848]

In the frontend, the TYPE_MIN/MAX_VALUE of ENUMERAL_TYPE is the same as
that of the enum's underlying type (see start_enum).  And the underlying
type of an enum is always known, even for an opaque enum that lacks a
definition.

But currently, we stream TYPE_MIN/MAX_VALUE of an enum only as part of
its definition.  So if the enum is declared but never defined, the
ENUMERAL_TYPE we stream in will have empty TYPE_MIN/MAX_VALUE fields
despite these fields being non-empty on stream out.

And even if the enum is defined, read_enum_def updates these fields only
on the main variant of the enum type, so for other variants (that we may
have streamed in earlier) these fields remain empty.  That these fields
are unexpectedly empty for some ENUMERAL_TYPEs is ultimately the cause
of the below two PRs.

This patch fixes this by making us stream TYPE_MIN/MAX_VALUE directly
for each ENUMERAL_TYPE rather than as part of the enum's definition, so
that we naturally also stream these fields for opaque enums (and each
enum type variant).

PR c++/106848
PR c++/102600

gcc/cp/ChangeLog:

* module.cc (trees_out::core_vals): Stream TYPE_MAX_VALUE and
TYPE_MIN_VALUE of ENUMERAL_TYPE.
(trees_in::core_vals): Likewise.
(trees_out::write_enum_def): Don't stream them here.
(trees_in::read_enum_def): Likewise.

gcc/testsuite/ChangeLog:

* g++.dg/modules/enum-9_a.H: New test.
* g++.dg/modules/enum-9_b.C: New test.
* g++.dg/modules/enum-10_a.H: New test.
* g++.dg/modules/enum-10_b.C: New test.
* g++.dg/modules/enum-11_a.H: New test.
* g++.dg/modules/enum-11_b.C: New test.
gcc/cp/module.cc
gcc/testsuite/g++.dg/modules/enum-10_a.H [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/enum-10_b.C [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/enum-11_a.H [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/enum-11_b.C [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/enum-9_a.H [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/enum-9_b.C [new file with mode: 0644]