From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by sourceware.org (Postfix) with ESMTPS id 6EAA7385841A for ; Mon, 22 Jan 2024 11:04:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6EAA7385841A 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 6EAA7385841A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::434 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705921463; cv=none; b=Jx+Oj2eOLnURBHxcM3MVOx9f8fm0DLWFYl31HWg/ucEJ8hErsjkBq6flBbR35bwNqNrshTflkm7XMrMcy2+LYMo3+DAUfq9zRlO8uOrEbLLO/gNa2V1PocQqEH9Z2Ck7rn9R4x+ilWyiN3S0SnzSxwe305AMbZcc16N9cQ4wHJI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705921463; c=relaxed/simple; bh=HGEXjMFGlyZ0wW+AyhS6snx5W4gIM3V+3hoRr/aMokE=; h=DKIM-Signature:Message-ID:Date:From:To:Subject:MIME-Version; b=cdMw7vZAFB41IEeH1nHkeoii2056LLBKZDszswTKAX3EXjr3n8XXYkp96gychjpZyuOKkDy1j1lOXES3b2MXe+Urq1Iw+V06rAKK/ouzT6N2vhFMK/7dIiy8twpOcUY27CtoPb1qsb3CpyFyIUgnhWGKKG4APVHeTZA3WDPt/n4= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-6dbdb1cb23fso1191126b3a.3 for ; Mon, 22 Jan 2024 03:04:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705921459; x=1706526259; 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=ZTf2bu3iLw1eNJZVKZppXmYt1+d3zh6+lBlkpcj1dWo=; b=SOhegx5oSks/CJEDl7/0MXrG1/P/FmmGQyWPlIK8y93jij9yRcb/3hJ9ex58Mq4wyK El8sWn1RonQHgJ/gtvCVGYpXmZbMT3Gf//iQiZQfL418WvGEbCjZg94eZfqnqs7yh+02 KPv6i+mRvL9FjyXfqSGJXCqTrKAZ6X4NJ+DeCZrtev/Ul1otMIIMANSgbKZSUfqOVH3I 9CbjwmSR/Lc8NoNBKEqAhRMKmC5o6DOXJ5oB+1qkmqABULGAYkZ6gcW5DPvXT4B8Asvt vpg+bIa9iQI1G5sFznNvih7KjUH48OGyKseQpqkvLWHlMSpZ7iFfGygtxmcVTkSu5stD NJVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705921459; x=1706526259; 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=ZTf2bu3iLw1eNJZVKZppXmYt1+d3zh6+lBlkpcj1dWo=; b=Z671/G5npO5uBxkuUdczxrHtia3R3JYVfw/7iFhKYrlC77n21yvcxE8ilbonKp8t6a we2iBunotaSaulh8IJ/l0KcappqGvDLYxn2AtIGIQaAcv6dZJI2pl9iNn/V12pb+N8s8 slPUP5P2/rdxKIw3n7+0jYsXv/5E4tXias3IhlSFpAcgacFYpTuzQ4b6jYduw+iQ+I05 8CzQJFwY/q2ONkxwHyca+dLpH2q/ldRD2R8Bjekbq09bcceme0cgWivl4TVxfTM+RbG6 jEUZUbkISTmeg71LJ+1pS+cnIBiY//HepkN6T3x2OZyTd/UCXmiyMfAL/eTEEpy83jbU veJA== X-Gm-Message-State: AOJu0Yy1JvwfmDNvH6cQHXNr1I6T9OMA5aLbbBcpUpueRueXz+5qiwZw G5HOgOABFky/22j7AXrsYR0e0C8JPHa9YSAG30pgkNj/6N4/2utA X-Google-Smtp-Source: AGHT+IF4VCYKaLgE1O/foPA3lZfc1OJA3rosiBd7rbi+LvPzOduXtgYLJ8SmOAvqQ4ql0+95pUcfiQ== X-Received: by 2002:a05:6a20:3c89:b0:19c:508a:c910 with SMTP id b9-20020a056a203c8900b0019c508ac910mr248521pzj.42.1705921459106; Mon, 22 Jan 2024 03:04:19 -0800 (PST) Received: from Thaum. (123-243-206-49.tpgi.com.au. [123.243.206.49]) by smtp.gmail.com with ESMTPSA id ph16-20020a17090b3bd000b0028e87ce1de0sm9207309pjb.51.2024.01.22.03.04.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 03:04:18 -0800 (PST) Message-ID: <65ae4bb2.170a0220.e245d.e0c4@mx.google.com> X-Google-Original-Message-ID: Date: Mon, 22 Jan 2024 22:04:13 +1100 From: Nathaniel Shead To: Jason Merrill Cc: Patrick Palka , gcc-patches@gcc.gnu.org, Nathan Sidwell Subject: Re: [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> <65a774d4.a70a0220.f1919.243b@mx.google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 Wed, Jan 17, 2024 at 10:51:16AM -0500, Jason Merrill wrote: > On 1/17/24 01:33, Nathaniel Shead wrote: > > 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. > > That sounds right for a module implementation unit or the GMF. > > > Bootstrapped and partially regtested on x86_64-pc-linux-gnu (so far only > > modules.exp): OK for trunk if full regtesting passes? > > Please add a reference to ABI issue 170 > (https://github.com/itanium-cxx-abi/cxx-abi/issues/170). OK with that > change if Nathan doesn't have any further comments this week. > Thanks. Here's what I'll push tomorrow unless I hear otherwise. -- >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 always 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. Some of this may need to change in the future to account for https://github.com/itanium-cxx-abi/cxx-abi/issues/170. 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 | 37 ++++++++++++++---------- 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, 64 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 8db662c0267..70785493561 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,23 @@ 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? + See also https://github.com/itanium-cxx-abi/cxx-abi/issues/170. + 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) @@ -12068,15 +12082,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