]> git.ipfire.org Git - thirdparty/gcc.git/commit
d: Fix undefined template references with circular module imports
authorIain Buclaw <ibuclaw@gdcproject.org>
Fri, 23 Oct 2020 07:41:11 +0000 (09:41 +0200)
committerIain Buclaw <ibuclaw@gdcproject.org>
Wed, 18 Nov 2020 09:20:01 +0000 (10:20 +0100)
commit96c4451b3284704567d9704bc5e91e7a1f307818
treee789267e793f73896b50af9d7b95717f92105127
parent04f9285d6ec93a417fc5eb83fbce273f4dfb0ce7
d: Fix undefined template references with circular module imports

In `TemplateInstance::semantic`, there exists special handling of
matching template instances for the same template declaration to ensure
that only at most one instance gets codegen'd.

If the primary instance `inst` originated from a non-root module, the
`minst` field will be updated so it is now coming from a root module,
however all Dsymbol `inst->members` of the instance still have their
`_scope->minst` pointing at the original non-root module. We must now
propagate `minst` to all members so that forward referenced dependencies
that get instantiated will also be appended to the root module,
otherwise there will be undefined references at link-time.

This doesn't affect compilations where all modules are compiled
together, as every module is a root module in that situation.  What this
primarily affects are cases where there is a mix of root and non-root
modules, and a template was first instantiated in a non-root context,
then later instantiated again in a root context.

gcc/d/ChangeLog:

* dmd/dtemplate.c (TemplateInstance::semantic): Propagate the root
module where the instantiated template should belong from the instance
to all member scopes.

gcc/testsuite/ChangeLog:

* gdc.test/compilable/imports/test21299/func.d: New test.
* gdc.test/compilable/imports/test21299/mtype.d: New test.
* gdc.test/compilable/imports/test21299/rootstringtable.d: New test.
* gdc.test/compilable/test21299a.d: New test.
* gdc.test/compilable/test21299b.d: New test.
* gdc.test/compilable/test21299c.d: New test.
* gdc.test/compilable/test21299d.d: New test.

(cherry picked from commit e419ede8915eeb879de3d9c026cd4213aaceb86a)
gcc/d/dmd/dtemplate.c
gcc/testsuite/gdc.test/compilable/imports/test21299/func.d [new file with mode: 0644]
gcc/testsuite/gdc.test/compilable/imports/test21299/mtype.d [new file with mode: 0644]
gcc/testsuite/gdc.test/compilable/imports/test21299/rootstringtable.d [new file with mode: 0644]
gcc/testsuite/gdc.test/compilable/test21299a.d [new file with mode: 0644]
gcc/testsuite/gdc.test/compilable/test21299b.d [new file with mode: 0644]
gcc/testsuite/gdc.test/compilable/test21299c.d [new file with mode: 0644]
gcc/testsuite/gdc.test/compilable/test21299d.d [new file with mode: 0644]