]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: Setup aliases imported from modules [PR106820]
authorNathaniel Shead <nathanieloshead@gmail.com>
Sat, 17 Feb 2024 12:10:49 +0000 (23:10 +1100)
committerNathaniel Shead <nathanieloshead@gmail.com>
Sun, 14 Apr 2024 10:55:33 +0000 (20:55 +1000)
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. But this patch fixes at least one missing step.

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 <nathanieloshead@gmail.com>
gcc/cp/module.cc
gcc/testsuite/g++.dg/modules/pr106820_a.H [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/pr106820_b.C [new file with mode: 0644]

index c6f71e11515c98b133657a51c6781d26d59bdf54..001430a4a8fe10c513f9eb703486a2b22b11a3b4 100644 (file)
@@ -219,6 +219,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"
@@ -8414,6 +8415,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 (file)
index 0000000..7d32d4e
--- /dev/null
@@ -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 (file)
index 0000000..247fe26
--- /dev/null
@@ -0,0 +1,8 @@
+// PR c++/106820
+// { dg-additional-options "-fmodules-ts" }
+
+import "pr106820_a.H";
+
+int main() {
+  __gthrw___pthread_key_create();
+}