From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oo1-xc29.google.com (mail-oo1-xc29.google.com [IPv6:2607:f8b0:4864:20::c29]) by sourceware.org (Postfix) with ESMTPS id 4C3343858D37 for ; Thu, 9 Nov 2023 23:45:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4C3343858D37 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=acm.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 4C3343858D37 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::c29 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699573555; cv=none; b=LRXQNm4M9m6nKFlT8C0yEQLurbp3HOTf6WGndlVn5L95ONlIqlFJmSZLmf9z4RgD5906Yhx2rl+ydcy6PKHNgRwrH8tnMdlAuPKqf5t8NE+Bs7Wp5vfbZ6SRgLTOQqtqdzhAQk8UjeSk79zu+9QyuqtYpSyzmxGIn8VFXZjDP+0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699573555; c=relaxed/simple; bh=hZYlpkoUDKRrZQp6Uf4Ya7XzOa7OepH1uyw+HzANEWc=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=M8BvFfwJMeKpQnm2rF4KF+01YLvGk/sM/TYVloA6bt0/uIGpbxkU7RQnGC4uy7cb3Ewm5/BBSmmV3ToXKeN/LRPLdTLQ87o4N2qouOTO6ho8ddo0nFZr/6DJDBR0Gm/E2Jp1Bw1zj0dBg1mE0MxwG5va+uCVP05yzgJ491i1ShU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-oo1-xc29.google.com with SMTP id 006d021491bc7-586beb5e6a7so799319eaf.1 for ; Thu, 09 Nov 2023 15:45:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1699573550; x=1700178350; darn=gcc.gnu.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :sender:from:to:cc:subject:date:message-id:reply-to; bh=t7FXaebQnDUSfAKB2fjxJOSTHCUCwvBBpo1Q3Rj62Pc=; b=Q+6kg44G859vPGaNdUAokIwNaXX8F3Qcu+CzCO2pM5u4Dwxyh4LkOjgkNdRX+XqPOz Q4GHI3c/dr6YqW3AN2EbrwftHHEroVLghzidSFPNjflO1hM8WYYUTVClfLPHX8mQd51I rZTz2jc/ep8L+y/LlHJRGb/VMiZm+TWrkDIsAHhKaY7GoetnqVWd2j/js7R02kBNMq8Q 3aQyx2OeLuJBEkBpJ45LkcbOD7fZ6DqNSLEXrvNW08sdxMDbCoK0P2kdJQDqxLTUZOXM fskrWjwWkdJO+H/zBjMkNmDtSeRsIGULwdlb/5DSadjRKDSxI41enrWWjYjJsZkSVh9r +AoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699573550; x=1700178350; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :sender:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=t7FXaebQnDUSfAKB2fjxJOSTHCUCwvBBpo1Q3Rj62Pc=; b=fjRJxFgSGkdyay3SCFDXuheBx3IsOl4eDby3Tn/O5l5Dd+nbHPFBair0WtN5KQMGsh mQGYPNv9DX7D83LI+r4TRV8y/3vfU7BFEbHwrTg4iwry96v2XuVgR4YXEb1GdH2tVfh/ RYtile+h8IZew3CebdgkI20m2mA1ToaN2NBmSG1kHtzNF1KgwVFT2L/xIcXWnM8+rAFq 3fqNPsZipNV0XhEPBdxGoN7TpYI/9v3hZxyW7WP4jq2/SEDAoSB4hm4ZgSBybu4oGOQS rrKqll268HU2rE+DdBlK7Tzw1Q/v9usIJLSUPxl6ptBs1KHZUz+PFFc18qtTNQsI7CRd YAYg== X-Gm-Message-State: AOJu0YwYZuX0y+u4C/nDHdC4XpqTw3YtJgdbPjxSFXJTIR8EtgPIqZJw kAZW+O+8kZEXb4pwoKDpkIY= X-Google-Smtp-Source: AGHT+IFl6WoHtthfi+celJFhPbRFMUhmgnCy+g5X7mBo+FS1Xoxgv1wfnkgIcvsMGjXtb+4fIFKJog== X-Received: by 2002:a05:6358:528f:b0:16b:4b12:1849 with SMTP id g15-20020a056358528f00b0016b4b121849mr7363232rwa.6.1699573550445; Thu, 09 Nov 2023 15:45:50 -0800 (PST) Received: from ?IPV6:2601:19c:5282:9160::4? ([2601:19c:5282:9160::4]) by smtp.googlemail.com with ESMTPSA id i4-20020a05620a0a0400b007757eddae8bsm291158qka.62.2023.11.09.15.45.49 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 09 Nov 2023 15:45:50 -0800 (PST) Sender: Nathan Sidwell Message-ID: <7c9b0dfd-c13b-4df0-b534-0ba851f5a184@acm.org> Date: Thu, 9 Nov 2023 18:45:49 -0500 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] c++/modules: fix virtual destructors [PR103499] Content-Language: en-US To: Nathaniel Shead Cc: gcc-patches@gcc.gnu.org, Jason Merrill References: <654cacb3.170a0220.9f692.95e6@mx.google.com> <19c6ccd9-f3c3-416a-9124-b827bf002a07@acm.org> <654d6b4b.620a0220.877d9.d8b2@mx.google.com> From: Nathan Sidwell In-Reply-To: <654d6b4b.620a0220.877d9.d8b2@mx.google.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3037.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,GIT_PATCH_0,HEADER_FROM_DIFFERENT_DOMAINS,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 11/9/23 18:29, Nathaniel Shead wrote: > On Thu, Nov 09, 2023 at 05:57:39PM -0500, Nathan Sidwell wrote: >> On 11/9/23 04:55, Nathaniel Shead wrote: >>> I'm not sure if this is just papering over a general issue of clones not being >>> exported/imported, or if this is just an exception to the general case of >>> clones being able to be freely regenerated with no other issues. >>> >>> Alternatively, would it be better to override the DECL_VINDEX of the original >>> declaration after filling it in for the clones as well? I wasn't able to see >>> anything depending on the current behaviour (though I didn't look very hard). >> >> I think your patch is a fine approach. IIRC just streaming out the clones >> directly ran into a bunch of issues, hence the current implementation. >> >> >> ok >> >> nathan > > Sorry, I don't have write access, would you be able to push? Thanks. > (And for my other patch.) ok, no worries > >>> >>> Bootstrapped and regtexted on x86_64-pc-linux-gnu. >>> >>> -- >8 -- >>> >>> Currently, cloned functions are not included in the CMI. However, for >>> virtual destructors the clones must have a different DECL_VINDEX from >>> their base declaration: the former have an INTEGER_CST indicating the >>> index into the vtable, while the latter indicate the FUNCTION_DECL that >>> they're overriding. >>> >>> As such, this patch ensures that DECL_VINDEX is properly passed on for >>> cloned functions as well to prevent this from causing issues. >>> >>> PR c++/103499 >>> >>> gcc/cp/ChangeLog: >>> >>> * module.cc (trees_out::decl_node): Write DECL_VINDEX for >>> virtual clones. >>> (trees_in::tree_node): Read DECL_VINDEX for virtual clones. >>> >>> gcc/testsuite/ChangeLog: >>> >>> * g++.dg/modules/pr103499_a.C: New test. >>> * g++.dg/modules/pr103499_b.C: New test. >>> >>> Signed-off-by: Nathaniel Shead >>> --- >>> gcc/cp/module.cc | 6 ++++++ >>> gcc/testsuite/g++.dg/modules/pr103499_a.C | 12 ++++++++++++ >>> gcc/testsuite/g++.dg/modules/pr103499_b.C | 8 ++++++++ >>> 3 files changed, 26 insertions(+) >>> create mode 100644 gcc/testsuite/g++.dg/modules/pr103499_a.C >>> create mode 100644 gcc/testsuite/g++.dg/modules/pr103499_b.C >>> >>> diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc >>> index c1c8c226bc1..416a7c414cc 100644 >>> --- a/gcc/cp/module.cc >>> +++ b/gcc/cp/module.cc >>> @@ -8648,6 +8648,8 @@ trees_out::decl_node (tree decl, walk_kind ref) >>> tree_node (target); >>> tree_node (DECL_NAME (decl)); >>> + if (TREE_CODE (decl) == FUNCTION_DECL && DECL_VIRTUAL_P (decl)) >>> + tree_node (DECL_VINDEX (decl)); >>> int tag = insert (decl); >>> if (streaming_p ()) >>> dump (dumper::TREE) >>> @@ -9869,6 +9871,10 @@ trees_in::tree_node (bool is_use) >>> } >>> } >>> + /* A clone might have a different vtable entry. */ >>> + if (res && TREE_CODE (res) == FUNCTION_DECL && DECL_VIRTUAL_P (res)) >>> + DECL_VINDEX (res) = tree_node (); >>> + >>> if (!res) >>> set_overrun (); >>> int tag = insert (res); >>> diff --git a/gcc/testsuite/g++.dg/modules/pr103499_a.C b/gcc/testsuite/g++.dg/modules/pr103499_a.C >>> new file mode 100644 >>> index 00000000000..0497c2c5504 >>> --- /dev/null >>> +++ b/gcc/testsuite/g++.dg/modules/pr103499_a.C >>> @@ -0,0 +1,12 @@ >>> +// PR c++/103499 >>> +// { dg-module-do compile } >>> +// { dg-additional-options "-fmodules-ts" } >>> +// { dg-module-cmi pr103499 } >>> + >>> +export module pr103499; >>> + >>> +export struct base { >>> + virtual ~base() = default; >>> +}; >>> + >>> +export struct derived : base {}; >>> diff --git a/gcc/testsuite/g++.dg/modules/pr103499_b.C b/gcc/testsuite/g++.dg/modules/pr103499_b.C >>> new file mode 100644 >>> index 00000000000..b7468562ba9 >>> --- /dev/null >>> +++ b/gcc/testsuite/g++.dg/modules/pr103499_b.C >>> @@ -0,0 +1,8 @@ >>> +// PR c++/103499 >>> +// { dg-additional-options "-fmodules-ts" } >>> + >>> +import pr103499; >>> + >>> +void test(derived* p) { >>> + delete p; >>> +} >> >> -- >> Nathan Sidwell >> -- Nathan Sidwell