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/devel/c++-modules] Fix type lang specific changing
Date: Thu, 27 Aug 2020 18:15:53 +0000 (GMT)	[thread overview]
Message-ID: <20200827181553.9DA073836C5C@sourceware.org> (raw)

https://gcc.gnu.org/g:2383be81dd8ab5e2ad677e8809963b5e81c0808c

commit 2383be81dd8ab5e2ad677e8809963b5e81c0808c
Author: Nathan Sidwell <nathan@acm.org>
Date:   Wed Aug 26 12:09:54 2020 -0700

    Fix type lang specific changing
    
            gcc/cp/
            * lex.c (copy_lang_type): Split allocation & assignment to be
            conditional-breakpoint friendly.
            * module.cc (trees_in::read_class_def): Update variants if we
            alter TYPE_LANG_SPECIFIC.
            * name-lookup.c (maybe_lazily_declare): Look at main variant's
            decl.
            gcc/testsuite/
            * g++.dg/modules/tdef-inst-1{.h,_[ab].C}: New.

Diff:
---
 ChangeLog.modules                            | 11 +++++++++++
 gcc/cp/lex.c                                 |  9 ++++-----
 gcc/cp/module.cc                             |  5 +++--
 gcc/cp/name-lookup.c                         |  9 +++++----
 gcc/testsuite/g++.dg/modules/tdef-inst-1.h   | 14 ++++++++++++++
 gcc/testsuite/g++.dg/modules/tdef-inst-1_a.C | 17 +++++++++++++++++
 gcc/testsuite/g++.dg/modules/tdef-inst-1_b.C |  9 +++++++++
 7 files changed, 63 insertions(+), 11 deletions(-)

diff --git a/ChangeLog.modules b/ChangeLog.modules
index 8e10010452e..c6ecb0a7241 100644
--- a/ChangeLog.modules
+++ b/ChangeLog.modules
@@ -1,5 +1,16 @@
 2020-08-26  Nathan Sidwell  <nathan@acm.org>
 
+	Fix type lang specific changing.
+	gcc/cp/
+	* lex.c (copy_lang_type): Split allocation & assignment to be
+	conditional-breakpoint friendly.
+	* module.cc (trees_in::read_class_def): Update variants if we
+	alter TYPE_LANG_SPECIFIC.
+	* name-lookup.c (maybe_lazily_declare): Look at main variant's
+	decl.
+	gcc/testsuite/
+	* g++.dg/modules/tdef-inst-1{.h,_[ab].C}: New.
+
 	Fix int_cst caching
 	gcc/
 	* tree.c (cache_integer_cst): Fix pointer type indices.
diff --git a/gcc/cp/lex.c b/gcc/cp/lex.c
index a45a39d0f59..013cbadf625 100644
--- a/gcc/cp/lex.c
+++ b/gcc/cp/lex.c
@@ -1036,8 +1036,7 @@ copy_lang_type (tree node)
   if (! TYPE_LANG_SPECIFIC (node))
     return;
 
-  struct lang_type *lt
-    = (struct lang_type *) ggc_internal_alloc (sizeof (struct lang_type));
+  auto *lt = (struct lang_type *) ggc_internal_alloc (sizeof (struct lang_type));
 
   memcpy (lt, TYPE_LANG_SPECIFIC (node), (sizeof (struct lang_type)));
   TYPE_LANG_SPECIFIC (node) = lt;
@@ -1069,9 +1068,9 @@ maybe_add_lang_type_raw (tree t)
   if (!RECORD_OR_UNION_CODE_P (TREE_CODE (t)))
     return false;
   
-  TYPE_LANG_SPECIFIC (t)
-    = (struct lang_type *) (ggc_internal_cleared_alloc
-			    (sizeof (struct lang_type)));
+  auto *lt = (struct lang_type *) (ggc_internal_cleared_alloc
+				   (sizeof (struct lang_type)));
+  TYPE_LANG_SPECIFIC (t) = lt;
 
   if (GATHER_STATISTICS)
     {
diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc
index 2ffb0f00da4..17c3fad89dd 100644
--- a/gcc/cp/module.cc
+++ b/gcc/cp/module.cc
@@ -11531,7 +11531,7 @@ trees_in::read_class_def (tree defn, tree maybe_template)
 	  TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)
 	    = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type_dup);
 
-	  if (TYPE_LANG_SPECIFIC (type_dup))
+	  if (auto ls = TYPE_LANG_SPECIFIC (type_dup))
 	    {
 	      if (TYPE_LANG_SPECIFIC (type))
 		{
@@ -11540,7 +11540,8 @@ trees_in::read_class_def (tree defn, tree maybe_template)
 		  CLASSTYPE_TYPEINFO_VAR (type_dup)
 		    = CLASSTYPE_TYPEINFO_VAR (type);
 		}
-	      TYPE_LANG_SPECIFIC (type) = TYPE_LANG_SPECIFIC (type_dup);
+	      for (tree v = type; v; v = TYPE_NEXT_VARIANT (v))
+		TYPE_LANG_SPECIFIC (v) = ls;
 	    }
 	}
 
diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c
index 55bd6b494e7..d7ec9d214ed 100644
--- a/gcc/cp/name-lookup.c
+++ b/gcc/cp/name-lookup.c
@@ -1846,10 +1846,11 @@ get_class_binding_direct (tree klass, tree name, bool want_type)
 static void
 maybe_lazily_declare (tree klass, tree name)
 {
-  if (DECL_LANG_SPECIFIC (TYPE_NAME (klass))
-      && DECL_MODULE_PENDING_MEMBERS_P (TYPE_NAME (klass)))
-    lazy_load_members (TYPE_NAME (klass));
-  
+  tree main_decl = TYPE_NAME (TYPE_MAIN_VARIANT (klass));
+  if (DECL_LANG_SPECIFIC (main_decl)
+      && DECL_MODULE_PENDING_MEMBERS_P (main_decl))
+    lazy_load_members (main_decl);
+
   /* Lazily declare functions, if we're going to search these.  */
   if (IDENTIFIER_CTOR_P (name))
     {
diff --git a/gcc/testsuite/g++.dg/modules/tdef-inst-1.h b/gcc/testsuite/g++.dg/modules/tdef-inst-1.h
new file mode 100644
index 00000000000..757113c0283
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/tdef-inst-1.h
@@ -0,0 +1,14 @@
+
+template <typename T>
+class basic_string;
+
+typedef basic_string<char> string;
+
+template <typename T>
+class basic_string
+{
+ public:
+  string Frob ();
+
+  basic_string (int);
+};
diff --git a/gcc/testsuite/g++.dg/modules/tdef-inst-1_a.C b/gcc/testsuite/g++.dg/modules/tdef-inst-1_a.C
new file mode 100644
index 00000000000..ab302bc1b6b
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/tdef-inst-1_a.C
@@ -0,0 +1,17 @@
+// { dg-additional-options -fmodules-ts }
+
+// The instantiation of the *definition* of basic_string is used in
+// importers, *after* they have instantiated a declaration of it *and*
+// created type variants.
+
+module;
+
+#include "tdef-inst-1.h"
+
+export module foo;
+// { dg-module-cmi foo }
+
+export inline int greeter (string const &bob)
+{
+  return sizeof (bob); // instantiates string
+}
diff --git a/gcc/testsuite/g++.dg/modules/tdef-inst-1_b.C b/gcc/testsuite/g++.dg/modules/tdef-inst-1_b.C
new file mode 100644
index 00000000000..ccf70520464
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/tdef-inst-1_b.C
@@ -0,0 +1,9 @@
+// { dg-additional-options -fmodules-ts }
+
+#include "tdef-inst-1.h"
+import foo;
+
+string Quux ()
+{
+  return 1; // failed to find converting ctor of string
+}


                 reply	other threads:[~2020-08-27 18:15 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=20200827181553.9DA073836C5C@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).