From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oi1-x229.google.com (mail-oi1-x229.google.com [IPv6:2607:f8b0:4864:20::229]) by sourceware.org (Postfix) with ESMTPS id C46843858CDB for ; Wed, 17 Jan 2024 06:33:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C46843858CDB Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C46843858CDB Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::229 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705473239; cv=none; b=MdUXWgbLltvZIB0vJxTMH0h+wji1AOswcb5CBp5XL3Oe+5CgkxvCVDu2hBVuoj6VvXHk7sv/60Zo8ofxlafjS1tuO+XBp5ybD10EW4G+E8CmLwj5fU4avZudyAHZ1CjcDqfQxm6pvg4aVnbV9QsxgfR3nkz3fl6WguAakPpl8SQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705473239; c=relaxed/simple; bh=xT5lw7i6E07ydX4VAzSSEGHvc9Af974cvQZrc5jiZfg=; h=DKIM-Signature:Message-ID:Date:From:To:Subject:MIME-Version; b=SW+4AjdABLV/TdWE6Rt+fgO8j8u6UxEtJf0iV109zd3LiWq3vVxbpNb4CcPu2PPZXKBiXVmDVoxi+J9yzn/8a+NZklPHo2kKIs/xP69zskBd/buRRjbCjmpFO3WySL+bLWE9ngCoUv0oCYsq9tY49au+KfSJfDVaFeRTxrMpZAw= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-oi1-x229.google.com with SMTP id 5614622812f47-3bb9d54575cso7210653b6e.2 for ; Tue, 16 Jan 2024 22:33:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705473237; x=1706078037; darn=gcc.gnu.org; h=in-reply-to:content-disposition:mime-version:references:subject:cc :to:from:date:message-id:from:to:cc:subject:date:message-id:reply-to; bh=y1PZaAMD0nPGjGV0GPYfkUH25rm3+sC6PbfT7GuH1E8=; b=bY7sT9SZy1JOpzfm0z8O/aLgY8voA+n7UNO9uYgG53tHgp/hAfwdk6cF5p6eFl+nc4 GIDxfwC7sI1plyDxl04ZWvZ7oQlqX5zrsC1dvxMpPI4yZOP/KhLG3eXyEagHQZYezN2t Lw2nQhyJSPMVVpDG651M9WUUcsUD/R1gu3UE5xrA7tUL5GCOj0ehRxSsRRKfsy1T7uix o1XphNxzuMIUpCvcXyQ81uUjvPQQP7P/nJmF529S3nGkEfj3kfQHOZFRvx8H9uuT5kX0 HVGIhNUPHXl9rAXJHpI8ElCAIqg7e5QQV4I656L/xm6XOMQOSdVuV8cyPzyBkq69VWX5 VPMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705473237; x=1706078037; h=in-reply-to:content-disposition:mime-version:references:subject:cc :to:from:date:message-id:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=y1PZaAMD0nPGjGV0GPYfkUH25rm3+sC6PbfT7GuH1E8=; b=B6VfqZ9QRZ+hY+rmteEqQNLggd1jyy8l6qv9YRNjRUSdsAze6qLzliy9WrxytAB5FZ wtEoihbP6CeNvf1c/GRuC+JgzOlmUbUjmDqUtneYZTHtk5oUKdMr1GvRpzd0iKF/mrio uqDVXsVPRjIRDqETxjTMYTufxi10EBkgJ8EZ8PehSMFa/2rsh8sc73gO+ltCB73msQ8k G88yh/SWWhuboFUeqPiqGDabC5YwB1KyVUupGPgG7lL08pmLSynDo8HuxbTZvAjohFA6 tvqmPLJzKIQiUB+G8kEiYcq7p8RuMY7EAMA39etZgR6KN13a4RGOh6X5CrHWufwy4bZB xvKw== X-Gm-Message-State: AOJu0YzFokZrjhMU4lGjb1t86jzEBNVrRDt7ed8YJkJ+jpRgYpTpTXi6 dBFHRrWmqDSFuXdSNigRBr8= X-Google-Smtp-Source: AGHT+IEu5tZJiaHyScMOtgeXoIxuM2p58jt9e5oaleUaTIkIxC6jfpgrrtGE3aJXaQXj5+YqtS/H4g== X-Received: by 2002:a05:6808:209b:b0:3bd:87f9:729 with SMTP id s27-20020a056808209b00b003bd87f90729mr2810627oiw.89.1705473236873; Tue, 16 Jan 2024 22:33:56 -0800 (PST) Received: from Thaum. (123-243-206-49.tpgi.com.au. [123.243.206.49]) by smtp.gmail.com with ESMTPSA id e9-20020aa78249000000b006dae568baedsm624048pfn.24.2024.01.16.22.33.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Jan 2024 22:33:56 -0800 (PST) Message-ID: <65a774d4.a70a0220.f1919.243b@mx.google.com> X-Google-Original-Message-ID: Date: Wed, 17 Jan 2024 17:33:51 +1100 From: Nathaniel Shead To: Jason Merrill Cc: Patrick Palka , gcc-patches@gcc.gnu.org, Nathan Sidwell Subject: [PATCH v3] c++/modules: Fix handling of extern templates in modules [PR112820] References: <656c78b2.170a0220.62689.59e8@mx.google.com> <659bc714.170a0220.c04dd.cc6a@mx.google.com> <6dc0c70c-1e12-275b-aff0-f06c42786bb0@idea> <7c45785c-f1e4-4e90-9a41-497433b7d5f7@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <7c45785c-f1e4-4e90-9a41-497433b7d5f7@redhat.com> X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE,URIBL_BLACK autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Mon, Jan 15, 2024 at 06:10:55PM -0500, Jason Merrill wrote: > Under what circumstances does it make sense for CLASSTYPE_INTERFACE_ONLY to > be set in the context of modules, anyway? We probably want to propagate it > for things in the global module so that various libstdc++ explicit > instantiations work the same with import std. > > For an class imported from a named module, this ties into the earlier > discussion about vtables and inlines that hasn't resolved yet in the ABI > committee. But it's certainly significantly interface-like. And I would > expect maybe_suppress_debug_info to suppress the debug info for such a class > on the assumption that the module unit has the needed debug info. > > Jason > Here's another approach for this patch. This still only fixes the specific issues in the PR, I think vtable handling etc. should wait till stage 1 because it involves a lot of messing around in decl2.cc. As mentioned in the commit message, after thinking more about it I don't think we (in general) want to propagate CLASSTYPE_INTERFACE_ONLY, even for declarations in the GMF. This makes sense to me because typically it can only be accurately determined at the end of the TU, which we haven't yet arrived at after importing. For instance, for a polymorphic class in the GMF without a key method, that we import from a module and then proceed to define the key method later on in this TU. Bootstrapped and partially regtested on x86_64-pc-linux-gnu (so far only modules.exp): OK for trunk if full regtesting passes? -- >8 -- Currently, extern templates are detected by looking for the DECL_EXTERNAL flag on a TYPE_DECL. However, this is incorrect: TYPE_DECLs don't actually set this flag, and it happens to work by coincidence due to TYPE_DECL_SUPPRESS_DEBUG happening to use the same underlying bit. This however causes issues with other TYPE_DECLs that also happen to have suppressed debug information. Instead, this patch reworks the logic so CLASSTYPE_INTERFACE_ONLY is always emitted into the module BMI and can then be used to check for an extern template correctly. Otherwise, for other declarations we want to redetermine this: even for declarations from the GMF, we may change our mind on whether to import or export depending on decisions made later in the TU after importing so we shouldn't decide this now, or necessarily reuse what the module we'd imported had decided. PR c++/112820 PR c++/102607 gcc/cp/ChangeLog: * module.cc (trees_out::lang_type_bools): Write interface_only and interface_unknown. (trees_in::lang_type_bools): Read the above flags. (trees_in::decl_value): Reset CLASSTYPE_INTERFACE_* except for extern templates. (trees_in::read_class_def): Remove buggy extern template handling. gcc/testsuite/ChangeLog: * g++.dg/modules/debug-2_a.C: New test. * g++.dg/modules/debug-2_b.C: New test. * g++.dg/modules/debug-2_c.C: New test. * g++.dg/modules/debug-3_a.C: New test. * g++.dg/modules/debug-3_b.C: New test. Signed-off-by: Nathaniel Shead --- gcc/cp/module.cc | 36 +++++++++++++----------- gcc/testsuite/g++.dg/modules/debug-2_a.C | 9 ++++++ gcc/testsuite/g++.dg/modules/debug-2_b.C | 8 ++++++ gcc/testsuite/g++.dg/modules/debug-2_c.C | 9 ++++++ gcc/testsuite/g++.dg/modules/debug-3_a.C | 8 ++++++ gcc/testsuite/g++.dg/modules/debug-3_b.C | 9 ++++++ 6 files changed, 63 insertions(+), 16 deletions(-) create mode 100644 gcc/testsuite/g++.dg/modules/debug-2_a.C create mode 100644 gcc/testsuite/g++.dg/modules/debug-2_b.C create mode 100644 gcc/testsuite/g++.dg/modules/debug-2_c.C create mode 100644 gcc/testsuite/g++.dg/modules/debug-3_a.C create mode 100644 gcc/testsuite/g++.dg/modules/debug-3_b.C diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc index 350ad15dc62..efc1d532a6e 100644 --- a/gcc/cp/module.cc +++ b/gcc/cp/module.cc @@ -5806,10 +5806,8 @@ trees_out::lang_type_bools (tree t) WB ((lang->gets_delete >> 0) & 1); WB ((lang->gets_delete >> 1) & 1); - // Interfaceness is recalculated upon reading. May have to revisit? - // How do dllexport and dllimport interact across a module? - // lang->interface_only - // lang->interface_unknown + WB (lang->interface_only); + WB (lang->interface_unknown); WB (lang->contains_empty_class_p); WB (lang->anon_aggr); WB (lang->non_zero_init); @@ -5877,9 +5875,8 @@ trees_in::lang_type_bools (tree t) v = b () << 0; v |= b () << 1; lang->gets_delete = v; - // lang->interface_only - // lang->interface_unknown - lang->interface_unknown = true; // Redetermine interface + RB (lang->interface_only); + RB (lang->interface_unknown); RB (lang->contains_empty_class_p); RB (lang->anon_aggr); RB (lang->non_zero_init); @@ -8246,6 +8243,22 @@ trees_in::decl_value () /* Set the TEMPLATE_DECL's type. */ TREE_TYPE (decl) = TREE_TYPE (inner); + /* Redetermine whether we need to import or export this declaration + for this TU. But for extern templates we know we must import: + they'll be defined in a different TU. + FIXME How do dllexport and dllimport interact across a module? + May have to revisit? */ + if (type + && CLASS_TYPE_P (type) + && TYPE_LANG_SPECIFIC (type) + && !(CLASSTYPE_EXPLICIT_INSTANTIATION (type) + && CLASSTYPE_INTERFACE_KNOWN (type) + && CLASSTYPE_INTERFACE_ONLY (type))) + { + CLASSTYPE_INTERFACE_ONLY (type) = false; + CLASSTYPE_INTERFACE_UNKNOWN (type) = true; + } + /* Add to specialization tables now that constraints etc are added. */ if (mk == MK_partial) @@ -12070,15 +12083,6 @@ trees_in::read_class_def (tree defn, tree maybe_template) bool installing = maybe_dup && !TYPE_SIZE (type); if (installing) { - if (DECL_EXTERNAL (defn) && TYPE_LANG_SPECIFIC (type)) - { - /* We don't deal with not-really-extern, because, for a - module you want the import to be the interface, and for a - header-unit, you're doing it wrong. */ - CLASSTYPE_INTERFACE_UNKNOWN (type) = false; - CLASSTYPE_INTERFACE_ONLY (type) = true; - } - if (maybe_dup != defn) { // FIXME: This is needed on other defns too, almost diff --git a/gcc/testsuite/g++.dg/modules/debug-2_a.C b/gcc/testsuite/g++.dg/modules/debug-2_a.C new file mode 100644 index 00000000000..eed0905542b --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/debug-2_a.C @@ -0,0 +1,9 @@ +// PR c++/112820 +// { dg-additional-options "-fmodules-ts -g" } +// { dg-module-cmi io } + +export module io; + +export struct error { + virtual const char* what() const noexcept; +}; diff --git a/gcc/testsuite/g++.dg/modules/debug-2_b.C b/gcc/testsuite/g++.dg/modules/debug-2_b.C new file mode 100644 index 00000000000..fc9afbc02e0 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/debug-2_b.C @@ -0,0 +1,8 @@ +// PR c++/112820 +// { dg-additional-options "-fmodules-ts -g" } + +module io; + +const char* error::what() const noexcept { + return "bla"; +} diff --git a/gcc/testsuite/g++.dg/modules/debug-2_c.C b/gcc/testsuite/g++.dg/modules/debug-2_c.C new file mode 100644 index 00000000000..37117f69dcd --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/debug-2_c.C @@ -0,0 +1,9 @@ +// PR c++/112820 +// { dg-module-do link } +// { dg-additional-options "-fmodules-ts -g" } + +import io; + +int main() { + error{}; +} diff --git a/gcc/testsuite/g++.dg/modules/debug-3_a.C b/gcc/testsuite/g++.dg/modules/debug-3_a.C new file mode 100644 index 00000000000..9e33d8260fd --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/debug-3_a.C @@ -0,0 +1,8 @@ +// PR c++/102607 +// { dg-additional-options "-fmodules-ts -g" } +// { dg-module-cmi mod } + +export module mod; +export struct B { + virtual ~B() = default; +}; diff --git a/gcc/testsuite/g++.dg/modules/debug-3_b.C b/gcc/testsuite/g++.dg/modules/debug-3_b.C new file mode 100644 index 00000000000..03c78b71b5d --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/debug-3_b.C @@ -0,0 +1,9 @@ +// PR c++/102607 +// { dg-module-do link } +// { dg-additional-options "-fmodules-ts -g" } + +import mod; +int main() { + struct D : B {}; + (void)D{}; +} -- 2.43.0