]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++/modules: Handle chaining already-imported local types [PR114630]
authorNathaniel Shead <nathanieloshead@gmail.com>
Thu, 9 Jan 2025 14:06:37 +0000 (01:06 +1100)
committerNathaniel Shead <nathanieloshead@gmail.com>
Sat, 11 Jan 2025 13:26:28 +0000 (00:26 +1100)
commit7c013a681cc138b8f191b75e408fe322d7fd998c
tree31b93c8a1cd5331598a8cf60dcfb4d8e9c41adb5
parent76167875f2f9c52db0c62f202bd8f766f1f74aad
c++/modules: Handle chaining already-imported local types [PR114630]

In the linked testcase, an ICE occurs because when reading the
(duplicate) function definition for _M_do_parse from module Y, the local
type definitions have already been streamed from module X and setup as
regular backreferences, rather than being found with find_duplicate,
causing issues with managing DECL_CHAIN.

It is tempting to just skip setting up the DECL_CHAIN for this case.
However, for the future it would be best to ensure that the block vars
for the duplicate definition are accurate, so that we could implement
ODR checking on function definitions at some point.

So to solve this, this patch creates a copy of the streamed-in local
type and chains that; it will be discarded along with the rest of the
duplicate function after we've finished processing.

A couple of suggested implementations from the discussion on the PR that
don't work:

- Replacing the `DECL_CHAIN` assertion with `(*chain && *chain != decl)`
  doesn't handle the case where type definitions are followed by regular
  local variables, since those won't have been imported as separate
  backreferences and so the chains will diverge.

- Correcting the purviewness of GMF template instantiations to force Y
  to emit copies of the local types rather than backreferences into X is
  insufficient, as it's still possible that the local types got streamed
  in a separate cluster to the function definition, and so will be again
  referred to via regular backreferences when importing.

- Likewise, preventing the emission of function definitions where an
  import has already provided that same definition also is insufficient,
  for much the same reason.

PR c++/114630

gcc/cp/ChangeLog:

* module.cc (trees_in::core_vals) <BLOCK>: Chain a new node if
DECL_CHAIN already is set.

gcc/testsuite/ChangeLog:

* g++.dg/modules/pr114630.h: New test.
* g++.dg/modules/pr114630_a.C: New test.
* g++.dg/modules/pr114630_b.C: New test.
* g++.dg/modules/pr114630_c.C: New test.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
Reviewed-by: Jason Merrill <jason@redhat.com>
Reviewed-by: Patrick Palka <ppalka@redhat.com>
gcc/cp/module.cc
gcc/testsuite/g++.dg/modules/pr114630.h [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/pr114630_a.C [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/pr114630_b.C [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/pr114630_c.C [new file with mode: 0644]