From patchwork Fri Mar 29 03:21:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathaniel Shead X-Patchwork-Id: 1917617 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=BtmYD4HF; 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 4V5QgG2RBsz1yXw for ; Fri, 29 Mar 2024 14:21:44 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 550303858D20 for ; Fri, 29 Mar 2024 03:21:41 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by sourceware.org (Postfix) with ESMTPS id DCAB03858D20 for ; Fri, 29 Mar 2024 03:21:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DCAB03858D20 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 DCAB03858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::634 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711682485; cv=none; b=sIClXp8tRnwjjicWz5269BTJ5xY70xDW8yMdF0In+KKRmMcEPzOCJsxd1cr23/Qrwt5m777pwSFrCDg/jvhBxfsYVc8gXQKojd/Xts7WI5vTwGfRNdWGYOc1kwQT+btJA3AQuGaK+uT1rY7hbOcxIu0a/7nqu5mAmSOL7yrZKzs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711682485; c=relaxed/simple; bh=XkvEYKNgUDgL6y/KYkGUhIBAaD/J8dkw0V+AQIYugMQ=; h=DKIM-Signature:Message-ID:Date:From:To:Subject:MIME-Version; b=LyIcZBJVWA+Rm3AixSsKmVx2h56CPv/P9l51nv6mPDukbxcz8Ve5nYVw39A4fzWauwBwGThKhvQGOshxmTa1p+jcxrOIH3orzJt/tDk9jJ0JYne8vYgnjTxJWon5NwU3UwvshPjqUZ1LLzmrH8r+mL0tMG0+EDD1BuatqxbGhxM= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-1e0189323b4so11326845ad.1 for ; Thu, 28 Mar 2024 20:21:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711682482; x=1712287282; 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=GWhhWXsyYXrbrNmZaJXVnufzj38N2fzgfcveWf6Yyjs=; b=BtmYD4HFIFnANjkTyxWhEWVcDYrAfDCfJO5PQ1RnuAEd7v2DZoPfSIwqYpZOtX8rYs gjl81fzGBIuQ5N1IJlNb9pIiie5o2/EXXZ5kgs9CmP9nrdk8bGsqzmh01E9qezA5vB6T xda+E1648FhPEAyPhhuKZa9Jv/PyP+rKAWaN7rgE1NOlxpNiXFh4qJY66xXfhCVuKWuJ 6yae38lwz9DfyCTMumqytDGyZokiKYbB+BGKtxuUI/NOm9TNpvBRFkh0mHZXUvBI+6lN vwIrQhs3i9tceEvjiVJqLT4FzBcoJzwSc3cxKurgv2mwixu0QkGqG2AHkmsxkY6QTPHZ Pbaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711682482; x=1712287282; 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=GWhhWXsyYXrbrNmZaJXVnufzj38N2fzgfcveWf6Yyjs=; b=UbWwD8LBvXjtFi1eW0MMztvGdeB46HZbcbY88dr/b1/ZMy9utDeKtrtKERcUgr1Z0K sVnOE2f/lpTjNOtGuX9vsErZM+LOO3gPAIHLAOKoFeISqJCY7bSI0GBhFolGp4gv5fJo 25vNdrz7NDvCeUjP7sLVuBK1Y+/Tv1bumrBGGrzMj7yk5gFl8CGnsBcRsCPx4Dy3QKoi lsmf7oFJrNpDZFlm6jm8hCaqKT9CuEzjVLo6yU75doqKD6ltVwA7vVTM5LCyRTAGz5zI XUVEDJhcvRxNLA2d8627jm1g1RTp8ervKX4To72OCUrAICd1MXtkOaxNZMOICsdK7wts ERHQ== X-Gm-Message-State: AOJu0YzrABJs2mahPweDEZJKvbQU7DLJy3XwZMzHKjkBJbU6wSVvPv47 m9v+iYEScRmxCSquDAzMilttey8l7W/gtKawFXH+3lohCz4ysf2Yxt7V1RRu X-Google-Smtp-Source: AGHT+IFg/H1Ql263cxZ/QFtJxJLBduAa+NHJPhXrd912Ren5SQgcdcDbA5hZTx5OzNu+24iG6ofx/Q== X-Received: by 2002:a17:902:6541:b0:1de:e954:c0e4 with SMTP id d1-20020a170902654100b001dee954c0e4mr1120780pln.63.1711682482428; Thu, 28 Mar 2024 20:21:22 -0700 (PDT) Received: from Thaum. (193-119-89-230.tpgi.com.au. [193.119.89.230]) by smtp.gmail.com with ESMTPSA id f8-20020a170902684800b001dd4d0082c8sm2436910pln.216.2024.03.28.20.21.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 20:21:21 -0700 (PDT) Message-ID: <660633b1.170a0220.717f3.817f@mx.google.com> X-Google-Original-Message-ID: Date: Fri, 29 Mar 2024 14:21:17 +1100 From: Nathaniel Shead To: gcc-patches@gcc.gnu.org Cc: Jason Merrill , Nathan Sidwell Subject: [PATCH] c++: Keep DECL_SAVED_TREE of destructor instantiations in modules [PR104040] MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-12.1 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 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 -- A template instantiation still needs to have its DECL_SAVED_TREE so that its definition is emitted into the CMI. This way it can be emitted in the object file of any importers that use it, in case it doesn't end up getting emitted in this TU. PR c++/104040 gcc/cp/ChangeLog: * semantics.cc (expand_or_defer_fn_1): Also keep DECL_SAVED_TREE for template instantiations. gcc/testsuite/ChangeLog: * g++.dg/modules/pr104040_a.C: New test. * g++.dg/modules/pr104040_b.C: New test. Signed-off-by: Nathaniel Shead Signed-off-by: Nathaniel Shead Reviewed-by: Jason Merrill Signed-off-by: Nathaniel Shead Reviewed-by: Jason Merrill --- gcc/cp/semantics.cc | 7 +++++-- gcc/testsuite/g++.dg/modules/pr104040_a.C | 14 ++++++++++++++ gcc/testsuite/g++.dg/modules/pr104040_b.C | 8 ++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/modules/pr104040_a.C create mode 100644 gcc/testsuite/g++.dg/modules/pr104040_b.C diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index adb1ba48d29..84e9901509a 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -5033,9 +5033,12 @@ expand_or_defer_fn_1 (tree fn) /* We don't want to process FN again, so pretend we've written it out, even though we haven't. */ TREE_ASM_WRITTEN (fn) = 1; - /* If this is a constexpr function, keep DECL_SAVED_TREE. */ + /* If this is a constexpr function, or the body might need to be + exported from a module CMI, keep DECL_SAVED_TREE. */ if (!DECL_DECLARED_CONSTEXPR_P (fn) - && !(modules_p () && DECL_DECLARED_INLINE_P (fn))) + && !(modules_p () + && (DECL_DECLARED_INLINE_P (fn) + || DECL_TEMPLATE_INSTANTIATION (fn)))) DECL_SAVED_TREE (fn) = NULL_TREE; return false; } diff --git a/gcc/testsuite/g++.dg/modules/pr104040_a.C b/gcc/testsuite/g++.dg/modules/pr104040_a.C new file mode 100644 index 00000000000..ea36ce0a798 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/pr104040_a.C @@ -0,0 +1,14 @@ +// PR c++/104040 +// { dg-additional-options "-fmodules-ts" } +// { dg-module-cmi test } + +export module test; + +export template +struct test { + ~test() {} +}; + +test use() { + return {}; +} diff --git a/gcc/testsuite/g++.dg/modules/pr104040_b.C b/gcc/testsuite/g++.dg/modules/pr104040_b.C new file mode 100644 index 00000000000..efe014673fb --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/pr104040_b.C @@ -0,0 +1,8 @@ +// PR c++/104040 +// { dg-additional-options "-fmodules-ts" } + +import test; + +int main() { + test t{}; +}