]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++/modules: Fix divergence in streaming/non-streaming tree walks [PR119608]
authorNathaniel Shead <nathanieloshead@gmail.com>
Fri, 4 Apr 2025 00:56:53 +0000 (11:56 +1100)
committerNathaniel Shead <nathanieloshead@gmail.com>
Fri, 4 Apr 2025 23:30:32 +0000 (10:30 +1100)
commitb8e8829cfb73d7aa009d387ab09bdbab221930d7
treeb7cdbcde888427b9c3bd8be75a46e5f1b9782503
parentf4a3ae1ef5ec951f007c4bd530f30e44945c5f0d
c++/modules: Fix divergence in streaming/non-streaming tree walks [PR119608]

Modules streaming walks decls multiple times, first as a non-streaming
walk to find dependencies, and then later to actually emit the decls.
The first walk needs to be done to note locations that will be emitted.

In the PR we are getting a checking ICE because we are streaming a decl
that we didn't initially walk when collecting dependencies, so the
location isn't in the noted locations map.  This is because in decl_node
we have a branch where a PARM_DECL that hasn't previously been
referenced gets walked by value only if 'streaming_p ()' is true.

The true root cause here is that the decltype(v) in the testcase refers
to a different PARM_DECL from the one in the declaration that we're
streaming; it's the PARM_DECL from the initial forward-declaration, that
we're not streaming.  A proper fix would be to ensure that it gets
remapped to the decl in the definition we're actually emitting, but for
now this workaround fixes the bug (and any other bugs that might
manifest similarly).

PR c++/119608

gcc/cp/ChangeLog:

* module.cc (trees_out::decl_node): Maybe require by-value
walking not just when streaming.

gcc/testsuite/ChangeLog:

* g++.dg/modules/pr119608_a.C: New test.
* g++.dg/modules/pr119608_b.C: New test.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
Reviewed-by: Jason Merrill <jason@redhat.com>
gcc/cp/module.cc
gcc/testsuite/g++.dg/modules/pr119608_a.C [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/pr119608_b.C [new file with mode: 0644]