Skip to content
Snippets Groups Projects
Commit d6d7e026 authored by Nathaniel Shead's avatar Nathaniel Shead
Browse files

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: default avatarNathaniel Shead <nathanieloshead@gmail.com>
Reviewed-by: default avatarJason Merrill <jason@redhat.com>
Reviewed-by: default avatarPatrick Palka <ppalka@redhat.com>
parent 65286465
No related branches found
No related tags found
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment