From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg1-x536.google.com (mail-pg1-x536.google.com [IPv6:2607:f8b0:4864:20::536]) by sourceware.org (Postfix) with ESMTPS id 5B8183858CD1 for ; Wed, 3 Apr 2024 00:58:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5B8183858CD1 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 5B8183858CD1 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::536 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712105882; cv=none; b=x9T4UzDFixagCWKLm19ek8DdtINcXkriQsm8LPjS421fYzWgtYws+h1j8z4P0X2KFNK6y6qEtf8OjecCKgAHa2acQEsLWSbg8xpYEFh2DknHlSUI8ES/D6rsXwX3NyQ3l3spLFbCFKmyqKhkxhPkhYAFdbhoSdXivseBoGfS1PY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712105882; c=relaxed/simple; bh=1W/RqDDXBYsqzlW8w1g2buVO9846yqp85U5/IZ2SvI4=; h=DKIM-Signature:Message-ID:Date:From:To:Subject:MIME-Version; b=qzO3ItqZKiWLlFvPuUp+az3gqAV8ZUaFIGBpmNMbRqHLGEFUcfUuXQIdQgOEH+Dn1eV14/TljdK2TGTjJj0d2CwOk8fYaLn1tkqyMOxPg/6iRmh8oLTczuPE/qiZTBjFPGMpUHd6UteGuxRetiQ80Prk/EN5fiJnd0Qaa0vj194= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pg1-x536.google.com with SMTP id 41be03b00d2f7-53fbf2c42bfso4512244a12.3 for ; Tue, 02 Apr 2024 17:58:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712105879; x=1712710679; 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=s0/v10pKRwdwawpY+uoU1wDKOgYDAeck8fYGOZi94DQ=; b=HRE3eGB1RW4xoQTa4QpGXuAuVEnvDS07+NUhJ+pjOozsfRb8H0iQjWORAIqxud2Ypw bUez/NdHt24YHsOTZKSygOwbYNwQYvZFLc3H2qhT5s5SUbkYbCdeLqTXXy+goMAi7F9/ Y7A3PS4ns7ZpSMpSx7FB76wfxcBf0eD+oT4K1PF8aoNpeSfoWB0PKyGteiDFCfeaRaXN 2tNRbAqJ2qiiTkGHffLGwe3ujk912+gihqhnOHFy1GYmWL2Fza7JUBLUz7oMnVlqSllP EQ1uKq5q2nA1qWfvwYhcHa3ZcmhWKtNSuepU+dE5QxJ4V6lGtKBWwuG87VOdxaO9HFCf Zt9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712105879; x=1712710679; 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=s0/v10pKRwdwawpY+uoU1wDKOgYDAeck8fYGOZi94DQ=; b=cKllMsvi8spilLCRW/enhFkeQj28/I5jB9dWlDV7bGudNcmXl0BXY07rpDFWztpNDL x2lhY/ajsq9Z/BlmVzQUn0xK7X8BsmZu+KAnTNIUBO1nb7t9Nk738hUkVQ5GYfIS/bx+ uowRnyszo5tljoGzC+auyBl3ZztEKqGpSKdOpQqjnNr1yHwzhgp2gT/qiB8tUkODOo8D gR1zIwjvasgDCEjsqcgqmX2vay2Riihhd4w0n1VNwqsx7Fh6l9c8/+hJq/UvQovJzYrk /dxyw+CSSGufNAGqUpg7aw2ggoE6o4bA99znZ1zxyujcMPvFzXHczHXb/kwr2RLwQuT/ 8S0Q== X-Gm-Message-State: AOJu0Yx32SJYazFuEr/OAyRTzTpKKj8FTRDx2r5W+G839UAynIghs+wq sA48MZbDVIba0uCOKVdMpyojjOInEtq+BjkChiGN54CW2V4ZKMjo X-Google-Smtp-Source: AGHT+IGDY0O0Xv9RoW5xEEcRqIREup+qNxfkaxyAf5/5VEkBtsg2rGqqb4fQIl2Ubh6PRfXtqojRQw== X-Received: by 2002:a05:6a20:3d11:b0:1a3:c4f8:7710 with SMTP id y17-20020a056a203d1100b001a3c4f87710mr1714345pzi.4.1712105879245; Tue, 02 Apr 2024 17:57:59 -0700 (PDT) Received: from Thaum. (193-119-89-230.tpgi.com.au. [193.119.89.230]) by smtp.gmail.com with ESMTPSA id j8-20020a170902da8800b001e205884ac6sm11777720plx.20.2024.04.02.17.57.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Apr 2024 17:57:58 -0700 (PDT) Message-ID: <660ca996.170a0220.60d95.0377@mx.google.com> X-Google-Original-Message-ID: Date: Wed, 3 Apr 2024 11:57:53 +1100 From: Nathaniel Shead To: Jason Merrill Cc: gcc-patches@gcc.gnu.org, Nathan Sidwell Subject: Re: [PATCH] c++: Keep DECL_SAVED_TREE of destructor instantiations in modules [PR104040] References: <660633b1.170a0220.717f3.817f@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=-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 List-Id: On Tue, Apr 02, 2024 at 01:18:17PM -0400, Jason Merrill wrote: > On 3/28/24 23:21, Nathaniel Shead wrote: > > 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 > > --- > > 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)))) > > How about using vague_linkage_p? > Right, of course. How about this? 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): Keep DECL_SAVED_TREE for all vague linkage functions. gcc/testsuite/ChangeLog: * g++.dg/modules/pr104040_a.C: New test. * g++.dg/modules/pr104040_b.C: New test. Signed-off-by: Nathaniel Shead Reviewed-by: Jason Merrill --- gcc/cp/semantics.cc | 5 +++-- gcc/testsuite/g++.dg/modules/pr104040_a.C | 14 ++++++++++++++ gcc/testsuite/g++.dg/modules/pr104040_b.C | 8 ++++++++ 3 files changed, 25 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..03800a20b26 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -5033,9 +5033,10 @@ 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 () && vague_linkage_p (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{}; +} -- 2.43.2