Internal-linkage entity mangling is entirely implementation defined --
there's no ABI issue.  Let's not mangle in any module attachment to
them, it makes the symbols unnecessarily longer.

nathan

--
Nathan Sidwell
From 8dc7e0287223bfe48f16cfc10ee87cd5ff05f277 Mon Sep 17 00:00:00 2001
From: Nathan Sidwell <nat...@acm.org>
Date: Wed, 6 Apr 2022 06:37:12 -0700
Subject: [PATCH] c++: Local symbols do not get module manglings

Internal-linkage entity mangling is entirely implementation defined --
there's no ABI issue.  Let's not mangle in any module attachment to
them, it makes the symbols unnecessarily longer.

      gcc/cp/
      * mangle.cc (maybe_write_module): Check external linkage.
      gcc/testsuite/
      * g++.dg/modules/mod-sym-4.C: New.
---
 gcc/cp/mangle.cc                         |  5 ++-
 gcc/testsuite/g++.dg/modules/mod-sym-4.C | 48 ++++++++++++++++++++++++
 2 files changed, 52 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/modules/mod-sym-4.C

diff --git a/gcc/cp/mangle.cc b/gcc/cp/mangle.cc
index eb53e0ebeb4..75388e99bfd 100644
--- a/gcc/cp/mangle.cc
+++ b/gcc/cp/mangle.cc
@@ -916,7 +916,10 @@ maybe_write_module (tree decl)
   if (!DECL_NAMESPACE_SCOPE_P (decl))
     return;
 
-  if (TREE_CODE (decl) == NAMESPACE_DECL && DECL_NAME (decl))
+  if (!TREE_PUBLIC (STRIP_TEMPLATE (decl)))
+    return;
+
+  if (TREE_CODE (decl) == NAMESPACE_DECL)
     return;
 
   int m = get_originating_module (decl, true);
diff --git a/gcc/testsuite/g++.dg/modules/mod-sym-4.C b/gcc/testsuite/g++.dg/modules/mod-sym-4.C
new file mode 100644
index 00000000000..fbf54d00171
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/mod-sym-4.C
@@ -0,0 +1,48 @@
+// { dg-additional-options -fmodules-ts }
+
+// internal linkage symbol mangling is unspecified, but let's try and
+// be unchanged from non-module internal mangling.
+
+export module A;
+// { dg-module-cmi A }
+
+// { dg-final { scan-assembler {_ZL6addonev:} } }
+static void addone () {}
+// { dg-final { scan-assembler {_ZL1x:} } }
+static int x = 5;
+
+namespace {
+// { dg-final { scan-assembler {_ZN12_GLOBAL__N_14frobEv:} } }
+void frob () {}
+// { dg-final { scan-assembler {_ZN12_GLOBAL__N_11yE:} } }
+int y = 2;
+struct Bill
+{
+  void F ();
+};
+// { dg-final { scan-assembler {_ZN12_GLOBAL__N_14Bill1FEv:} } }
+void Bill::F() {}
+}
+
+// { dg-final { scan-assembler {_ZL4FrobPN12_GLOBAL__N_14BillE:} } }
+static void Frob (Bill *b)
+{
+  if (b) b->F();
+}
+
+namespace N {
+// { dg-final { scan-assembler {_ZN1NL5innerEv:} } }
+static void inner() {}
+// { dg-final { scan-assembler {_ZN1NL1zE:} } }
+static int z = 3;
+}
+
+// { dg-final { scan-assembler {_ZW1A6addsixv:} } }
+void addsix ()
+{
+  Frob(nullptr);
+  frob();
+  addone();
+  void(x + y + N::z);
+  N::inner();
+}
-- 
2.30.2

Reply via email to