]> gcc.gnu.org Git - gcc.git/commitdiff
c++: Local symbols do not get module manglings
authorNathan Sidwell <nathan@acm.org>
Wed, 6 Apr 2022 13:37:12 +0000 (06:37 -0700)
committerNathan Sidwell <nathan@acm.org>
Fri, 13 May 2022 14:18:52 +0000 (07:18 -0700)
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
gcc/testsuite/g++.dg/modules/mod-sym-4.C [new file with mode: 0644]

index eb53e0ebeb435f011e5d53177908e852212f601f..75388e99bfd962a80695e762c8cf3600b53b07b2 100644 (file)
@@ -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 (file)
index 0000000..fbf54d0
--- /dev/null
@@ -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();
+}
This page took 0.076194 seconds and 5 git commands to generate.