From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1059) id 9DA073836C5C; Thu, 27 Aug 2020 18:15:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9DA073836C5C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1598552153; bh=C9jLzsVLxO7be/n9OJzU9S0LSh9fJV9+p5pl6Qt5ifw=; h=From:To:Subject:Date:From; b=ydvT/c+vp5yPX00C3ubrOVZta91CgodORX/hVLOxv/HzUKqRgE7jROj4gN8OTgIOk GVjcc23BOsyQx5HuFda3kQh7Ct0fXWWVmc5NitV3sBU7BhWhALitbGEInoiSepFahG mMjF5q4/H4F5Dfj+Z9zCB4UuuOTJCt9ufzZVZoGc= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Nathan Sidwell To: gcc-cvs@gcc.gnu.org Subject: [gcc/devel/c++-modules] Fix type lang specific changing X-Act-Checkin: gcc X-Git-Author: Nathan Sidwell X-Git-Refname: refs/heads/devel/c++-modules X-Git-Oldrev: ee7260fe55e7c49fc2a05cea38612db0845c56bd X-Git-Newrev: 2383be81dd8ab5e2ad677e8809963b5e81c0808c Message-Id: <20200827181553.9DA073836C5C@sourceware.org> Date: Thu, 27 Aug 2020 18:15:53 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 27 Aug 2020 18:15:53 -0000 https://gcc.gnu.org/g:2383be81dd8ab5e2ad677e8809963b5e81c0808c commit 2383be81dd8ab5e2ad677e8809963b5e81c0808c Author: Nathan Sidwell 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 + 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 +class basic_string; + +typedef basic_string string; + +template +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 +}