From patchwork Sun Dec 3 12:46:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathaniel Shead X-Patchwork-Id: 1871035 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=GJJIwNAl; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SjmlW11Qhz23p4 for ; Sun, 3 Dec 2023 23:47:00 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2BFB9384F99D for ; Sun, 3 Dec 2023 12:46:58 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) by sourceware.org (Postfix) with ESMTPS id 6F25F3858C35 for ; Sun, 3 Dec 2023 12:46:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6F25F3858C35 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 6F25F3858C35 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::42b ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701607606; cv=none; b=DMMeYG/Cw+cly4F355kfaqxgp2MCH0ZUPPAa4s6oynlRwleC7wFfKHzdga18n2UAcZLfv4uYIW74gBRk0BFiLQpMNa5GvCRwJCXfNwgfqz6o/orFhS3HI67HuohLYYCFfhtleNbcq2ZGqIY+MhPOYJ9kuC2S9WNzChjNiAmLS4k= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701607606; c=relaxed/simple; bh=K+DgeHipG7K0KS/ry816w11k7juMGrMz8oqj36tpBwc=; h=DKIM-Signature:Message-ID:Date:From:To:Subject:MIME-Version; b=sZuDYMGrrSXCPbt43GaWQSNbn/FMhiMHW9nToN98RhMB7e8JiP9OCddLALizUtbpHR0Pjhd88acXj7IdLmQejq2X3H6y1rnYkLhcHWY9R9VNX3YPNifGNl31Y3Tyfm8W2yoj/u84MMFtb2/vrWSUQBfttx0kA2y1KPcC/5ouGbc= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-6cddb35ef8bso2842151b3a.2 for ; Sun, 03 Dec 2023 04:46:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701607603; x=1702212403; darn=gcc.gnu.org; h=content-disposition:mime-version:subject:cc:to:from:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=Pk3Jkb4K+69vKOIsbdmGCPa6Z5romPvEkvWKF6yTyaM=; b=GJJIwNAljwdFMv+0Dx38ZHbDe5Z38LaU1/iXgIu2UVvzBkA4DgiRBtTpH6mA2+4K3m dTxeYD+36ZOP5xl6RmjQ+uZDy9YT0piRnwGEAyi8ox4DrTlSMdEh9kSUhTabc6MG6Vst WG7ttkq7ZJzRK1RPt4HIyaYgv8tzRpNWSaCltf4nEFqS0xwkwFpAouOCKzM+Gb8XRupz wA7mEm7JxxpR1y9ErHWkADRfMGz8rY1b7LW4e1kKzRCllVZg0iDeujdruZk1TZiHuGQ3 at/FnpBGrkTJKfUBs5jAN0Kash+ixXN1ItYEtTn05sCjQbklAeN2QGM5rCjwcsZhTbnQ lP3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701607603; x=1702212403; h=content-disposition:mime-version:subject:cc:to:from:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Pk3Jkb4K+69vKOIsbdmGCPa6Z5romPvEkvWKF6yTyaM=; b=cAK3p94J/6+w+tSQ3bhnW9vRoZtzL1AnbaGVtxLRbX7nK4bIIf3BeyH/TNzVXnW5NV zXLLM8VYP9LOVJ/peWuCQ6HCRWMUo2Y0XqVk8anzamLHyQM/s+D1KlPteZJnvPrUjWbe EJRyBLFg4nh/fnkr50QNcvJ4UDLbLyLKufdqGhoLGZmc9/z8E3vj+Ll09xCqs4Enb5ZF X/U0irZpeTJ8hyr32tj41bHqF/gV0vgyGZoz7K2UA0a92ora+HGJqUo277frzd4eKGQt MQByVaU06/XsHuXgVWUCWQcqTDbHDLESvSsvNSCkcxdNpHs1KMEhLGr/5r0PDBq6Rcn4 jPDA== X-Gm-Message-State: AOJu0YyNTH0psuQsx5+JFxiipCl6U04tHv0IOL22aR+b7nEid+ZxEmWF lGoS25kcpXxxr1otttfb9uTYj3cYjZs= X-Google-Smtp-Source: AGHT+IHWRjxJGkEdwK+58sK1ZNOcQpgPFrmmuLyj97eg/2EmkNCOrtxgNwqYBWsNFWd7aZzmgro6Ew== X-Received: by 2002:a05:6a20:394a:b0:18f:457b:7ad3 with SMTP id r10-20020a056a20394a00b0018f457b7ad3mr66980pzg.51.1701607603066; Sun, 03 Dec 2023 04:46:43 -0800 (PST) Received: from Thaum. ([203.166.236.30]) by smtp.gmail.com with ESMTPSA id z14-20020a170903018e00b001cfcd4eca11sm2808671plg.114.2023.12.03.04.46.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 04:46:42 -0800 (PST) Message-ID: <656c78b2.170a0220.62689.59e8@mx.google.com> X-Google-Original-Message-ID: Date: Sun, 3 Dec 2023 23:46:36 +1100 From: Nathaniel Shead To: gcc-patches@gcc.gnu.org Cc: Jason Merrill , Nathan Sidwell Subject: [PATCH] c++/modules: Prevent treating suppressed debug info as extern template [PR112820] MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-11.2 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Bootstrapped and regtested on x86_64-pc-linux-gnu, OK for trunk? -- >8 -- The TYPE_DECL_SUPPRESS_DEBUG and DECL_EXTERNAL flags use the same underlying bit. This is causing confusion when attempting to determine the interface for a streamed-in class type, since the modules code currently assumes that all DECL_EXTERNAL types are extern templates. However, when -g is specified then TYPE_DECL_SUPPRESS_DEBUG (and hence DECL_EXTERNAL) is marked on various other kinds of declarations, such as vtables, which causes them to never be emitted. This patch constrains the checks for DECL_EXTERNAL for this to only consider template instantiations, thus avoiding the issue. PR c++/102607 PR c++/112820 gcc/cp/ChangeLog: * module.cc (trees_in::read_class_def): Only set interface for template instantiations. 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 | 4 +++- 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, 46 insertions(+), 1 deletion(-) 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 33fcf396875..257f39421d0 100644 --- a/gcc/cp/module.cc +++ b/gcc/cp/module.cc @@ -12041,7 +12041,9 @@ 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)) + if (DECL_EXTERNAL (defn) + && TYPE_LANG_SPECIFIC (type) + && CLASSTYPE_TEMPLATE_INSTANTIATION (type)) { /* We don't deal with not-really-extern, because, for a module you want the import to be the interface, and for a 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{}; +}