From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id DCE8D385842A for ; Tue, 9 Apr 2024 14:28:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DCE8D385842A Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org DCE8D385842A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712672888; cv=none; b=ixfO47Aaa3wxZYoC25yraIgTDAIlrI1qSRiUpe/507QntlI/ZDC5vwJX8RYpQ7V3mWJEoErS3xaTR2fjnYa6UBknTO5i9Z6DAKDUJL8jlotfOn5AhJFkWltyy/FcR9sVuxvZouggrZFaG3Lt+wcIyUkkCP8mOG2/P6qm1yFVRq4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712672888; c=relaxed/simple; bh=EsilLRM/yJsXXmhsE6Vf4pMfZq2sud31cG90rP+DPOk=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=SEgTkGFbaED9yK2Dt6u64mOE9v66xKvI/dGHpHFPtyfK7NUeOhmsmJnhu3mpmDqt7/iWs1+o8hogcol6hVV4RDpG8fBN7XSkkoC7wF2QOI/2lCeeh6guHj0Pc0dAMbapp3w4xWxRmlS+x6K8cF9vMCGfii1dXJBUoY2RW79Sjoo= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712672885; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YeinmM6xbLbzoUBPKH3kodnptvBOrlAFAiEfR9/3rIA=; b=K74sZwXTtTA8wuJU9WojzXyYLGl2W6rsMOkNCnUuaI3OYSeh3sxEZYGFuNxLphQ5oxX1Mw F5WRGab0fwzDNZgISgDEilj7ubFgKIzvx1J9jhhDoMpahDep/wVw6Pt+9c4z/cXUHV/I9u TK/IWxQfReK17Nx0OhpamqqSvhCa+sI= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-631-JWK1OoKQNhGC1QdFCnkuKw-1; Tue, 09 Apr 2024 10:28:04 -0400 X-MC-Unique: JWK1OoKQNhGC1QdFCnkuKw-1 Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-4348f25d3cdso22710261cf.0 for ; Tue, 09 Apr 2024 07:28:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712672883; x=1713277683; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=YeinmM6xbLbzoUBPKH3kodnptvBOrlAFAiEfR9/3rIA=; b=ZDe0TJw2YYWqhyoiY+pBYPJNgW4f5sEQJxtx9DjcgdSWNKywI7RY5t9T4SVj66iecF dw+DYgCuzt60uboN1q5qq3DInHol6HzTHiBi8BDVBExCtZzpcEAZylNi6e0Ye6/sg2Jl gxadsRuG1dyzCaH0MocuIXns6chVFpl3nWwRIbJL8mJxZo7Y4/4Jvp5jvQDdc01PstQE kEi7UbNjf8vyrJE40+oyEnmwLd1sJ1odJDWA5bZDj5VEKiyyDy7nT6s5HyU2llvVVin/ XkAo8BRp7YRlY9LDxmYNxtgI9u2+ewbI0kBqUIclA3jaIl9nQiPDeMO6AoKoVVqa0/gf zViA== X-Gm-Message-State: AOJu0Yz9FfTVpsOUmrGu0MXpy0MjI745EmU7jcMbCzU8IbNLS1y5/fQk A+dXdkv7z+KGGYvGQXYDE/0D4TVDY0sbRnTrGBXnNoAV329MsZUg4ovjgto5hz53ssVwjUX7fxA 01QMKpF+bYcXAacEXWI0XBuDMH9l2pbyh/unpcQ0sw6Ec8zktAeJO8oE= X-Received: by 2002:ac8:7fd5:0:b0:432:e65e:bacc with SMTP id b21-20020ac87fd5000000b00432e65ebaccmr15391616qtk.58.1712672883553; Tue, 09 Apr 2024 07:28:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE7xyBOuvBqL7RSAQ3JIKWC9gmUpf/bzr2zzYL0QmANMSvgkqxjgAKjhLuY1Dd8urAdvwXuDA== X-Received: by 2002:ac8:7fd5:0:b0:432:e65e:bacc with SMTP id b21-20020ac87fd5000000b00432e65ebaccmr15391598qtk.58.1712672883224; Tue, 09 Apr 2024 07:28:03 -0700 (PDT) Received: from [192.168.1.130] (130-44-146-16.s12558.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.146.16]) by smtp.gmail.com with ESMTPSA id cp4-20020a05622a420400b0043167d8c57dsm4668264qtb.56.2024.04.09.07.28.02 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 09 Apr 2024 07:28:02 -0700 (PDT) Message-ID: <4fc6ea10-190f-4ca9-8555-5a9ae8d01e93@redhat.com> Date: Tue, 9 Apr 2024 10:28:01 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] c++: Keep DECL_SAVED_TREE of destructor instantiations in modules [PR104040] To: Nathaniel Shead Cc: gcc-patches@gcc.gnu.org, Nathan Sidwell References: <660633b1.170a0220.717f3.817f@mx.google.com> <660ca996.170a0220.60d95.0377@mx.google.com> <6ea38b8a-4146-4c02-b28a-80f1de178e01@redhat.com> <660e8ec1.170a0220.2a0c4.3501@mx.google.com> <40220469-1dfe-4d3f-9a3d-686a074f80b9@redhat.com> <66154447.050a0220.1e34e.720c@mx.google.com> From: Jason Merrill In-Reply-To: <66154447.050a0220.1e34e.720c@mx.google.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,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 4/9/24 09:36, Nathaniel Shead wrote: > On Mon, Apr 08, 2024 at 11:17:27PM -0400, Jason Merrill wrote: >> On 4/4/24 07:27, Nathaniel Shead wrote: >>> On Wed, Apr 03, 2024 at 11:18:01AM -0400, Jason Merrill wrote: >>>> On 4/2/24 20:57, Nathaniel Shead wrote: >>>>> On Tue, Apr 02, 2024 at 01:18:17PM -0400, Jason Merrill wrote: >>>>>> On 3/28/24 23:21, Nathaniel Shead wrote: >>>>>>> - && !(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))) >>>> >>>> Also, how about module_maybe_has_cmi_p? OK with that change. >>> >>> Using 'module_maybe_has_cmi_p' doesn't seem to work. This is for two >>> reasons, one of them fixable and one of them not (easily): >>> >>> - It seems that header modules don't count for 'module_maybe_has_cmi_p'; >>> I didn't notice this initially, and maybe they should for the >>> no-linkage decls too? >> >> I think so; they could similarly be referred to by an importer. >> > > I'll investigate further and make a patch and test for this when I get a > chance then. > >>> But even accounting for this, >>> >>> - For some reason only clearing it if the module might have a CMI causes >>> crashes in importers for some testcases. I'm not 100% sure why yet, >>> but I suspect it might be some duplicate-decls thing where the type >>> inconsistently has DECL_SAVED_TREE applied, since this is also called >>> on streamed-in declarations. >> >> Clearing if the module might have a CMI sounds backwards, I'd expect that to >> be the case where we want to leave it alone. Is that the problem, or just a >> typo? >> > > Sorry typo, yes. I've tried the following incremental patch: > > diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc > index 5a862a3ee5f..3341ade4e33 100644 > --- a/gcc/cp/semantics.cc > +++ b/gcc/cp/semantics.cc > @@ -5036,7 +5036,8 @@ expand_or_defer_fn_1 (tree fn) > /* 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 () && vague_linkage_p (fn))) > + && !((module_maybe_has_cmi_p () || header_module_p ()) > + && vague_linkage_p (fn))) > DECL_SAVED_TREE (fn) = NULL_TREE; > return false; > } > > and this causes ICEs with e.g. testsuite/g++.dg/modules/concept-6_b.C, > where maybe_clone_body is called with a NULL cfun. I think one of the > post-load processing loops might have cleared cfun before it got called? > Not sure, haven't looked too hard; I can dig in further later if you > would like. Looking at the testcase, I guess the problem is that we parse the header, clone the constructor, throw away the cloned body, then import the same cloned constructor, merge it with the one with the body discarded, try to clone the result, and fail. Perhaps we want to avoid trying to clone after merging? For now, the last patch is OK with the comment adjustment mentioned below. >>> Out of interest, what was the reason that it was cleared at all in the >>> first place? I wasn't able to find anything with git blame; is it just >>> for performance reasons in avoiding excess lowering later? >> >> That change goes back to the LTO merge, I believe it was to reduce >> unnecessary LTO streaming. >> >> But now that I think about it some more, I don't see why handling modules >> specially here is necessary at all; the point of this code is that after we >> build the destructor clones, the DECL_SAVED_TREE of the cloned function is >> no longer useful. Why would modules care about the maybe-in-charge >> function? > > The current modules implementation doesn't stream the clones: instead > it always just streams the maybe-in-charge functions (including its > tree) and recreates the clones on import. I believe Nathan said that > there were issues with streaming the clones directly, see > https://gcc.gnu.org/pipermail/gcc-patches/2023-November/635882.html Aha, please add that to the comment. Jason