On Fri, Apr 12, 2024 at 03:54:21PM -0400, Jason Merrill wrote: > On 3/26/24 09:24, Nathaniel Shead wrote: > > > > I wonder if more generally we need to be doing more work when importing > > definitions from header units especially to handle all the work that > > 'make_rtl_for_nonlocal_decl' and 'rest_of_decl_compilation' would have > > been performing. > > Can we just call those functions? >
Probably at least 'rest_of_decl_compilation' can (should?) be called from modules, but I haven't worked out exactly in which circumstances yet and whether there's any other work it does that doesn't make sense in a modules context. I don't think 'make_rtl_for_nonlocal_decl' can easily be called directly though. At the very least it'll probably need to get called in `read_definition` which doesn't clash with aliases (which are never definitions, as far as I can tell), so this will still be necessary. > > But this patch fixes at least one missing step. > > OK. > Thanks, pushed as r14-9959-g62a0ef0d02cbb7. > > PR c++/106820 > > > > gcc/cp/ChangeLog: > > > > * module.cc (trees_in::decl_value): Assemble alias when needed. > > > > gcc/testsuite/ChangeLog: > > > > * g++.dg/modules/pr106820_a.H: New test. > > * g++.dg/modules/pr106820_b.C: New test. > > > > Signed-off-by: Nathaniel Shead <nathanielosh...@gmail.com> > > --- > > gcc/cp/module.cc | 9 +++++++++ > > gcc/testsuite/g++.dg/modules/pr106820_a.H | 5 +++++ > > gcc/testsuite/g++.dg/modules/pr106820_b.C | 8 ++++++++ > > 3 files changed, 22 insertions(+) > > create mode 100644 gcc/testsuite/g++.dg/modules/pr106820_a.H > > create mode 100644 gcc/testsuite/g++.dg/modules/pr106820_b.C > > > > diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc > > index 8aab9ea0bae..b4e3b38c6fe 100644 > > --- a/gcc/cp/module.cc > > +++ b/gcc/cp/module.cc > > @@ -217,6 +217,7 @@ Classes used: > > #include "dumpfile.h" > > #include "bitmap.h" > > #include "cgraph.h" > > +#include "varasm.h" > > #include "tree-iterator.h" > > #include "cpplib.h" > > #include "mkdeps.h" > > @@ -8302,6 +8303,14 @@ trees_in::decl_value () > > if (state->is_header () > > && decl_tls_wrapper_p (decl)) > > note_vague_linkage_fn (decl); > > + > > + /* Setup aliases for the declaration. */ > > + if (tree alias = lookup_attribute ("alias", DECL_ATTRIBUTES (decl))) > > + { > > + alias = TREE_VALUE (TREE_VALUE (alias)); > > + alias = get_identifier (TREE_STRING_POINTER (alias)); > > + assemble_alias (decl, alias); > > + } > > } > > else > > { > > diff --git a/gcc/testsuite/g++.dg/modules/pr106820_a.H > > b/gcc/testsuite/g++.dg/modules/pr106820_a.H > > new file mode 100644 > > index 00000000000..7d32d4e5fc3 > > --- /dev/null > > +++ b/gcc/testsuite/g++.dg/modules/pr106820_a.H > > @@ -0,0 +1,5 @@ > > +// PR c++/106820 > > +// { dg-additional-options "-fmodules-ts" } > > +// { dg-module-cmi {} } > > + > > +static int __gthrw___pthread_key_create() > > __attribute__((__weakref__("foo"))); > > diff --git a/gcc/testsuite/g++.dg/modules/pr106820_b.C > > b/gcc/testsuite/g++.dg/modules/pr106820_b.C > > new file mode 100644 > > index 00000000000..247fe26e778 > > --- /dev/null > > +++ b/gcc/testsuite/g++.dg/modules/pr106820_b.C > > @@ -0,0 +1,8 @@ > > +// PR c++/106820 > > +// { dg-additional-options "-fmodules-ts" } > > + > > +import "pr106820_a.H"; > > + > > +int main() { > > + __gthrw___pthread_key_create(); > > +} >