public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* c++: Local symbols do not get module manglings
@ 2022-05-13 14:19 Nathan Sidwell
  0 siblings, 0 replies; only message in thread
From: Nathan Sidwell @ 2022-05-13 14:19 UTC (permalink / raw)
  To: GCC Patches

[-- Attachment #1: Type: text/plain, Size: 215 bytes --]

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

[-- Attachment #2: 0001-c-Local-symbols-do-not-get-module-manglings.patch --]
[-- Type: text/x-patch, Size: 2578 bytes --]

From 8dc7e0287223bfe48f16cfc10ee87cd5ff05f277 Mon Sep 17 00:00:00 2001
From: Nathan Sidwell <nathan@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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-05-13 14:19 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-13 14:19 c++: Local symbols do not get module manglings Nathan Sidwell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).