public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Nathan Sidwell <nathan@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r12-7496] c++: Standard mangling abbreviations & modules
Date: Fri,  4 Mar 2022 20:00:15 +0000 (GMT)	[thread overview]
Message-ID: <20220304200015.6505A3858D39@sourceware.org> (raw)

https://gcc.gnu.org/g:591d2130348b15ec9158bb69a7fd9442bb81fa3a

commit r12-7496-g591d2130348b15ec9158bb69a7fd9442bb81fa3a
Author: Nathan Sidwell <nathan@acm.org>
Date:   Wed Mar 2 19:42:23 2022 -0500

    c++: Standard mangling abbreviations & modules
    
    The std manglings for things like std::string should not apply if
    we're not in the global module.
    
    gcc/cp/
            * mangle.cc (is_std_substitution): Check global module.
            (is_std_substitution_char): Return bool.
    gcc/testsuite/
            * g++.dg/modules/std-subst-2.C: New.
            * g++.dg/modules/std-subst-3.C: New.
            * g++.dg/modules/std-subst-4_a.C: New.
            * g++.dg/modules/std-subst-4_b.C: New.
            * g++.dg/modules/std-subst-4_c.C: New.

Diff:
---
 gcc/cp/mangle.cc                             | 32 +++++++++++++++++---------
 gcc/testsuite/g++.dg/modules/std-subst-2.C   | 13 +++++++++++
 gcc/testsuite/g++.dg/modules/std-subst-3.C   | 34 ++++++++++++++++++++++++++++
 gcc/testsuite/g++.dg/modules/std-subst-4_a.C | 14 ++++++++++++
 gcc/testsuite/g++.dg/modules/std-subst-4_b.C | 14 ++++++++++++
 gcc/testsuite/g++.dg/modules/std-subst-4_c.C | 16 +++++++++++++
 6 files changed, 112 insertions(+), 11 deletions(-)

diff --git a/gcc/cp/mangle.cc b/gcc/cp/mangle.cc
index 6657ce4d983..dbcec0a55bc 100644
--- a/gcc/cp/mangle.cc
+++ b/gcc/cp/mangle.cc
@@ -180,9 +180,9 @@ static tree maybe_template_info (const tree);
 
 static inline tree canonicalize_for_substitution (tree);
 static void add_substitution (tree);
-static inline int is_std_substitution (const tree,
+static inline bool is_std_substitution (const tree,
 				       const substitution_identifier_index_t);
-static inline int is_std_substitution_char (const tree,
+static inline bool is_std_substitution_char (const tree,
 					    const substitution_identifier_index_t);
 static int find_substitution (tree);
 static void mangle_call_offset (const tree, const tree);
@@ -467,9 +467,10 @@ add_substitution (tree node)
 
 /* Helper function for find_substitution.  Returns nonzero if NODE,
    which may be a decl or a CLASS_TYPE, is a template-id with template
-   name of substitution_index[INDEX] in the ::std namespace.  */
+   name of substitution_index[INDEX] in the ::std namespace, with
+   global module attachment.  */
 
-static inline int
+static bool
 is_std_substitution (const tree node,
 		     const substitution_identifier_index_t index)
 {
@@ -488,13 +489,22 @@ is_std_substitution (const tree node,
     }
   else
     /* These are not the droids you're looking for.  */
-    return 0;
+    return false;
+
+  if (!DECL_NAMESPACE_STD_P (CP_DECL_CONTEXT (decl)))
+    return false;
+
+  if (!(TYPE_LANG_SPECIFIC (type) && TYPE_TEMPLATE_INFO (type)))
+    return false;
 
-  return (DECL_NAMESPACE_STD_P (CP_DECL_CONTEXT (decl))
-	  && TYPE_LANG_SPECIFIC (type)
-	  && TYPE_TEMPLATE_INFO (type)
-	  && (DECL_NAME (TYPE_TI_TEMPLATE (type))
-	      == subst_identifiers[index]));
+  tree tmpl = TYPE_TI_TEMPLATE (type);
+  if (DECL_NAME (tmpl) != subst_identifiers[index])
+    return false;
+
+  if (modules_p () && get_originating_module (tmpl, true) >= 0)
+    return false;
+
+  return true;
 }
 
 /* Return the ABI tags (the TREE_VALUE of the "abi_tag" attribute entry) for T,
@@ -526,7 +536,7 @@ get_abi_tags (tree t)
    ::std::identifier<char>, where identifier is
    substitution_index[INDEX].  */
 
-static inline int
+static bool
 is_std_substitution_char (const tree node,
 			  const substitution_identifier_index_t index)
 {
diff --git a/gcc/testsuite/g++.dg/modules/std-subst-2.C b/gcc/testsuite/g++.dg/modules/std-subst-2.C
new file mode 100644
index 00000000000..e7c77063a93
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/std-subst-2.C
@@ -0,0 +1,13 @@
+// { dg-additional-options "-fmodules-ts" }
+export module FOO;
+// { dg-module-cmi FOO }
+namespace Outer {
+class Y;
+class Inner {
+  class X;
+  void Fn (X &, Y &); // #2
+};
+void Inner::Fn (X &, Y &) {}
+}
+
+// { dg-final { scan-assembler {_ZN5OuterW3FOO5Inner2FnERNS1_1XERNS_S0_1YE:} } }
diff --git a/gcc/testsuite/g++.dg/modules/std-subst-3.C b/gcc/testsuite/g++.dg/modules/std-subst-3.C
new file mode 100644
index 00000000000..75b81acf2f6
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/std-subst-3.C
@@ -0,0 +1,34 @@
+// { dg-additional-options "-fmodules-ts -Wno-pedantic" }
+
+module;
+# 5 __FILE__ 1
+class Pooh;
+class Piglet;
+# 8 "" 2
+
+export module std; // might happen, you can't say it won't!
+// { dg-module-cmi std }
+
+namespace std {
+export template<typename T> class allocator {
+// just for testing, not real!
+void M (T *);
+template <typename U> U *N (T *);
+};
+
+template<typename T> void allocator<T>::M (T *) {}
+template<typename T> template<typename U> U *allocator<T>::N (T *) {
+return nullptr;
+}
+
+template void allocator<int>::M (int *);
+template float *allocator<int>::N<float> (int *);
+}
+
+template void std::allocator<Pooh>::M (Pooh *);
+template Piglet *std::allocator<Pooh>::N<Piglet> (Pooh *);
+
+// { dg-final { scan-assembler {_ZNStW3std9allocatorIiE1MEPi:} } }
+// { dg-final { scan-assembler {_ZNStW3std9allocatorIiE1NIfEEPT_Pi:} } }
+// { dg-final { scan-assembler {_ZNStW3std9allocatorI4PoohE1MEPS1_:} } }
+// { dg-final { scan-assembler {_ZNStW3std9allocatorI4PoohE1NI6PigletEEPT_PS1_:} } }
diff --git a/gcc/testsuite/g++.dg/modules/std-subst-4_a.C b/gcc/testsuite/g++.dg/modules/std-subst-4_a.C
new file mode 100644
index 00000000000..d7520f41b2c
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/std-subst-4_a.C
@@ -0,0 +1,14 @@
+// { dg-additional-options "-fmodules-ts -Wno-pedantic" }
+
+module;
+# 5 __FILE__ 1
+namespace std {
+template <typename A> struct allocator {};
+template <typename C, typename T, typename A>
+class basic_string;
+} // namespace std
+# 12 "" 2
+export module RenameString;
+// { dg-module-cmi RenameString }
+export template <typename C, typename T>
+using str = std::basic_string<C, T, std::allocator<C>>;
diff --git a/gcc/testsuite/g++.dg/modules/std-subst-4_b.C b/gcc/testsuite/g++.dg/modules/std-subst-4_b.C
new file mode 100644
index 00000000000..5bea86ff6aa
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/std-subst-4_b.C
@@ -0,0 +1,14 @@
+// { dg-additional-options -fmodules-ts }
+
+export module Foo;
+// { dg-module-cmi Foo }
+import RenameString;
+
+namespace std {
+template <typename T> struct char_traits {};
+} // namespace std
+
+// use Sb mangling, not Ss as this is not global-module std::char_traits.
+// { dg-final { scan-assembler {_ZW3Foo1fRSbIcStS_11char_traitsIcESaIcEE:} } }
+void f(str<char, std::char_traits<char>> &s) {
+}
diff --git a/gcc/testsuite/g++.dg/modules/std-subst-4_c.C b/gcc/testsuite/g++.dg/modules/std-subst-4_c.C
new file mode 100644
index 00000000000..21beb9bbb1c
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/std-subst-4_c.C
@@ -0,0 +1,16 @@
+// { dg-additional-options "-fmodules-ts -Wno-pedantic" }
+module;
+# 5 __FILE__ 1
+namespace std {
+template <typename A> struct char_traits {};
+} // namespace std
+# 9 "" 2
+export module Bar;
+// { dg-module-cmi Bar }
+import RenameString;
+
+// Use Ss as this is global-module std::char_traits
+void g(str<char, std::char_traits<char>> &s) {
+}
+
+// { dg-final { scan-assembler {_ZW3Bar1gRSs:} } }


                 reply	other threads:[~2022-03-04 20:00 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220304200015.6505A3858D39@sourceware.org \
    --to=nathan@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).