From patchwork Tue Aug 20 23:38:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathaniel Shead X-Patchwork-Id: 1974616 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=dDURyoQX; 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 4WpQsf2QrLz1yYZ for ; Wed, 21 Aug 2024 09:39:17 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DA086387088C for ; Tue, 20 Aug 2024 23:39:14 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by sourceware.org (Postfix) with ESMTPS id 89E493858433 for ; Tue, 20 Aug 2024 23:38:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 89E493858433 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 89E493858433 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::102c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724197134; cv=none; b=r2RvmAvx4tIUcJX1DycsRI6jVu5YlXS3AiXuiEObkJPsNs/gcc17VlaLW1GsElbc1s7lKdVUgRvF2H0IqJz1ajp4FomSuKfgKrn1nej8YYZwXqmgHWxLCdfezaxhcv5bvgQN9M21u74bZ2/fCW2fNWUd/NxyKSDX1SeDlORHcjM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724197134; c=relaxed/simple; bh=qb7494d5m0CHdeF6UW44RtSUziVUk5DGixgFPygQUCU=; h=DKIM-Signature:Message-ID:Date:From:To:Subject:MIME-Version; b=VnJDfPw+fdtnkEJrcjI96e3G3WoQdcOL3Qy94E8yFH34OTpbGa+SEVtpRYjPaE587CWcqyLXwtPWT/4zuAmHv2BGauM/eMxgOhjk9nLoQ6M1G1ux65RhoDoN6X3LyTS2SvOQpaR7JCT22zZtLeJU27IG0jAnSLnl9ofqDm4EL8g= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pj1-x102c.google.com with SMTP id 98e67ed59e1d1-2d3bc9405c2so26565a91.2 for ; Tue, 20 Aug 2024 16:38:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724197129; x=1724801929; 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=OwecyBazbQ0TAmcqSNEei2gvZ9yOHDtt/k73+gwMRt8=; b=dDURyoQX9oftYmHc8qLEr7qHzr1MU+zYPGWyAMhnXnhCxo/NyOXX7JqtghoyuGf1gk h43NDoVlpMJD6YRzZrS3KdrPFUQ9FCeZSmPyQDUObKiw7vSI4BarezLl38m0XNe60Cy8 AHUxWN1nL3zMmZgpv7oelqEhFWZ7wtArKqoGtji7NDUZkXmC+W35l9vGRV4DrqomiZTL snlCA9jIdcvdWiFJXN+T8LIlRMX4OxaLIFoAoxJ6gEpD9zo/UtlsNzvh5fCYlEUFNGa+ No/Dmo5XDbRymsYsGCVuMhi2ARsHOED9v4Fz3m3X9Y9hT/BDptokeiEqcZWBwC7JZ08M fFMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724197129; x=1724801929; 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=OwecyBazbQ0TAmcqSNEei2gvZ9yOHDtt/k73+gwMRt8=; b=jF61+kZOZqsVhGUyLSs2WtUlcEzB+zeHupTFTrQQyrZojl5n0t13/4EFAbKV8AmJUp d3jBURA5VRKGHR0CpaNsOxM2uL1lYXEsqH8Lm9EKP4DFjc3rzCbnQZg/tr8ZRolH7yPv HjPcnO5cGugL0KJrajv+lfyE2UF1YMNNj6nVKMLZPV+pszWNHNoL0e/hHwwy905sXntE 35VLitvP819m/1ZaJ7DfD+IxtUAs8jx6kodzaS6Ulg5ofRz+xXtEY+aoJQjtsqWtQlOm Xn16Hmb8/SECQ7Z6WkMflxuT5Wu4/i9GWk6Ta1KdOMmUSl2kiCzmiW4zisha/QCqugxK Ql1A== X-Gm-Message-State: AOJu0YxbnEFbwZ3SdXjTGpf+EDBvYUdD64OX7uQ66SHS2iBPdRGzAtbB fpC2i2Hl8y+jvQL7M/aMCcnzqe5ql/jAalx8e+BR6jptWOnnMDkfFTI/eQ== X-Google-Smtp-Source: AGHT+IH/2G0M2VJt3HwKnVt03+2JP+Vkcg3rxL7a5dQYWJIt+LKTnT/mxl9RY75boqbR5ivbcegU7A== X-Received: by 2002:a05:6a20:7348:b0:1c4:f30e:97ff with SMTP id adf61e73a8af0-1cada1f1452mr400617637.9.1724197129314; Tue, 20 Aug 2024 16:38:49 -0700 (PDT) Received: from Thaum. (110-175-236-231.static.tpgi.com.au. [110.175.236.231]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-201f02faa39sm82704315ad.37.2024.08.20.16.38.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Aug 2024 16:38:48 -0700 (PDT) Message-ID: <66c52908.170a0220.2c87fb.d675@mx.google.com> X-Google-Original-Message-ID: Date: Wed, 21 Aug 2024 09:38:44 +1000 From: Nathaniel Shead To: gcc-patches@gcc.gnu.org Cc: Jason Merrill Subject: [PATCH 1/3] c++: Handle ABI for non-polymorphic dynamic classes MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-12.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 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 Itanium ABI has specific rules for when virtual tables for dynamic classes should be emitted. However we didn't consider structures with virtual inheritance but no virtual members as dynamic classes for ABI purposes; this patch fixes this. gcc/cp/ChangeLog: * decl2.cc (import_export_class): Use TYPE_CONTAINS_VPTR_P instead of TYPE_POLYMORPHIC_P. (import_export_decl): Likewise. gcc/testsuite/ChangeLog: * g++.dg/modules/virt-5_a.C: New test. * g++.dg/modules/virt-5_b.C: New test. Signed-off-by: Nathaniel Shead --- gcc/cp/decl2.cc | 4 ++-- gcc/testsuite/g++.dg/modules/virt-5_a.C | 16 ++++++++++++++++ gcc/testsuite/g++.dg/modules/virt-5_b.C | 11 +++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/modules/virt-5_a.C create mode 100644 gcc/testsuite/g++.dg/modules/virt-5_b.C diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc index e9ae979896c..af544f40dac 100644 --- a/gcc/cp/decl2.cc +++ b/gcc/cp/decl2.cc @@ -2431,7 +2431,7 @@ import_export_class (tree ctype) translation unit, then export the class; otherwise, import it. */ import_export = -1; - else if (TYPE_POLYMORPHIC_P (ctype)) + else if (TYPE_CONTAINS_VPTR_P (ctype)) { tree cdecl = TYPE_NAME (ctype); if (DECL_LANG_SPECIFIC (cdecl) && DECL_MODULE_ATTACH_P (cdecl)) @@ -3527,7 +3527,7 @@ import_export_decl (tree decl) class_type = type; import_export_class (type); if (CLASSTYPE_INTERFACE_KNOWN (type) - && TYPE_POLYMORPHIC_P (type) + && TYPE_CONTAINS_VPTR_P (type) && CLASSTYPE_INTERFACE_ONLY (type) /* If -fno-rtti was specified, then we cannot be sure that RTTI information will be emitted with the diff --git a/gcc/testsuite/g++.dg/modules/virt-5_a.C b/gcc/testsuite/g++.dg/modules/virt-5_a.C new file mode 100644 index 00000000000..f4c6abe85ef --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/virt-5_a.C @@ -0,0 +1,16 @@ +// { dg-additional-options "-fmodules-ts" } +// { dg-module-cmi M } + +export module M; + +struct C {}; +struct B : virtual C {}; + +// Despite no non-inline key function, this is still a dynamic class +// and so by the Itanium ABI 5.2.3 should be uniquely emitted in this TU +export struct A : B { + inline A (int) {} +}; + +// { dg-final { scan-assembler {_ZTTW1M1A:} } } +// { dg-final { scan-assembler {_ZTVW1M1A:} } } diff --git a/gcc/testsuite/g++.dg/modules/virt-5_b.C b/gcc/testsuite/g++.dg/modules/virt-5_b.C new file mode 100644 index 00000000000..785dd92ac1e --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/virt-5_b.C @@ -0,0 +1,11 @@ +// { dg-module-do link } +// { dg-additional-options "-fmodules-ts" } + +import M; + +int main() { + A a(0); +} + +// { dg-final { scan-assembler-not {_ZTTW1M1A:} } } +// { dg-final { scan-assembler-not {_ZTVW1M1A:} } } From patchwork Tue Aug 20 23:40:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathaniel Shead X-Patchwork-Id: 1974617 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=QlyYtTCC; 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 4WpQvS6Tbjz1yXf for ; Wed, 21 Aug 2024 09:40:52 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BE7043858433 for ; Tue, 20 Aug 2024 23:40:50 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by sourceware.org (Postfix) with ESMTPS id 8F2343870853 for ; Tue, 20 Aug 2024 23:40:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8F2343870853 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 8F2343870853 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::1035 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724197232; cv=none; b=Hunx7/tj0zdM6Wi5XLjajU2w7DPM4NgobeKQlcyhBZyvYHKxbzyM4kJAPV2DUaR+D5YJtv27P7vyQtupnSLn3jAAygQhPjl8Jk21ATTGWbKwJXcdOshKcovYk1fAKiCdVswVIPg+0grVR3znznoXqK6ZbCkcYbny9uIrCn8Mt0Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724197232; c=relaxed/simple; bh=ciBAUC2iNOOWbXHJyiG7NHsa2PEoG1BeMVAqHF7oFwQ=; h=DKIM-Signature:Message-ID:Date:From:To:Subject:MIME-Version; b=dkspn0pGokpXY5tsKyg1xkz5/goOJdNjjLxLqDkJQTnUFxo05hHW0DoB3vw4PUQ3SLfeDuqQBE3huN4V0BqVNS4CIGdTDIGC/JMXezqQavqFP8F6/oYGPZanK36MKpkr66tdfkSD0TMPOHBzQG4XupSIxjvmGzNxnW/dg+App1Y= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pj1-x1035.google.com with SMTP id 98e67ed59e1d1-2d3cc6170eeso43563a91.1 for ; Tue, 20 Aug 2024 16:40:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724197229; x=1724802029; 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=NK1nlYxeetEjw598H8Y+/wh0tyq7ystZeP//MukBqQ4=; b=QlyYtTCCQXIm4FP8lTcRVqZSWdWXKhAKFrcEVmLX9gXkip7W7qBd4Xq44u63IIK9C9 0ViMw5JDbZDWAYqVw4jWvpYUb+YWEy9lRPXMnpAtMPA9GNGrJThhcNQIhQqo8CB+qKNl pA/gtAGclI/CAQotwNg51s9MdBIosM3s6hCkyIeTDOF521oByJ47wqc1vp3wG4NjIs8r y/whu78lqgR/iAMoy3/bGMUrQL7O0VJOAaAoUCrZAwd+EgGPmYGSJRyin2ZbDd3ekBM7 xWU1vNPHobj1LjQPSzHuk+pW678tcPUvtwQGaul27xX9UeOt227toj6fsUiK00fm76cN gAlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724197229; x=1724802029; 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=NK1nlYxeetEjw598H8Y+/wh0tyq7ystZeP//MukBqQ4=; b=rmpjONjIouQZxVdER+C7mg+JCgdFc7+6gve33Dosl95L9PpoPYn5V/yb6jQU2gwGv/ F/JE2biSWWuDzCqqlKYwlHeknAtkb7JbC96w5Gx58al8eOPPRHDGYfRzYjxKzPgeG7MQ XHBJn1OUCPAiLblHVVmmuh7NoWVrPfVPFyMctllu5IHXjcqhw2bmgQhNiRttQG5d0yBH FvOcdJIz2Li/e/uzQgvq2AmpscG+xprqTcWyJVgXcYCLy8wV1BpAsCsuFK1SDLrG2tYp nOehOP5/lxjUdkk1EbGRE3FJhBToKLoQcMGKV4A7U8bDDLgYpU37FOtL7ou1xJh6U3l6 HIKA== X-Gm-Message-State: AOJu0YwgjSHteftoCs/7BEaJLJlWLF0R6T0hlslTzlWiBVDuxJETzPpG E6gEcqQExYNH/ay69BkTDDOGbFZQ39i08Nu8JaAykAWKqGGBcT6EVocAeg== X-Google-Smtp-Source: AGHT+IFuXdEiHFX/v9E6r4W2t0A0jvEoX21xnQu5UgsqHO5qWx4kzs4BnXWtqFAx11jz+gkgKwW7hw== X-Received: by 2002:a17:90a:1116:b0:2d3:da94:171 with SMTP id 98e67ed59e1d1-2d5ea8a5da1mr361990a91.5.1724197229403; Tue, 20 Aug 2024 16:40:29 -0700 (PDT) Received: from Thaum. (110-175-236-231.static.tpgi.com.au. [110.175.236.231]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2d5eb917006sm204047a91.12.2024.08.20.16.40.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Aug 2024 16:40:29 -0700 (PDT) Message-ID: <66c5296d.170a0220.3bae0d.0cdc@mx.google.com> X-Google-Original-Message-ID: Date: Wed, 21 Aug 2024 09:40:25 +1000 From: Nathaniel Shead To: gcc-patches@gcc.gnu.org Cc: Jason Merrill , Nathan Sidwell Subject: [PATCH 2/3] c++/modules: Prevent maybe_clone_decl being called multiple times [PR115007] References: <66c52908.170a0220.2c87fb.d675@mx.google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <66c52908.170a0220.2c87fb.d675@mx.google.com> X-Spam-Status: No, score=-12.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 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 ICE in the linked PR is caused because maybe_clone_decl is not prepared to be called on a declaration that has already had clones created; what happens otherwise is that start_preparsed_function early exits and never sets up cfun, causing a segfault later on. To fix this we ensure that post_load_processing only calls maybe_clone_decl if TREE_ASM_WRITTEN has not been marked on the declaration yet, and (if maybe_clone_decls succeeds) marks this flag on the decl so that it doesn't get called again later when finalising deferred vague linkage declarations in c_parse_final_cleanups. As a bonus this now allows us to only keep the DECL_SAVED_TREE around in expand_or_defer_fn_1 for modules which have CMIs, which will have benefits for LTO performance in non-interface TUs. For clarity we also update the streaming code to do post_load_decls for maybe in-charge cdtors rather than any DECL_ABSTRACT_P declaration, as this is more accurate to the decls affected by maybe_clone_body. PR c++/115007 gcc/cp/ChangeLog: * module.cc (module_state::read_cluster): Replace DECL_ABSTRACT_P with DECL_MAYBE_IN_CHARGE_CDTOR_P. (post_load_processing): Check and mark TREE_ASM_WRITTEN. * semantics.cc (expand_or_defer_fn_1): Use the more specific module_maybe_has_cmi_p instead of modules_p. gcc/testsuite/ChangeLog: * g++.dg/modules/virt-6_a.C: New test. * g++.dg/modules/virt-6_b.C: New test. Signed-off-by: Nathaniel Shead --- gcc/cp/module.cc | 7 ++++--- gcc/cp/semantics.cc | 2 +- gcc/testsuite/g++.dg/modules/virt-6_a.C | 13 +++++++++++++ gcc/testsuite/g++.dg/modules/virt-6_b.C | 6 ++++++ 4 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/g++.dg/modules/virt-6_a.C create mode 100644 gcc/testsuite/g++.dg/modules/virt-6_b.C diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc index 7c42aea05ee..5cd4f313933 100644 --- a/gcc/cp/module.cc +++ b/gcc/cp/module.cc @@ -15525,7 +15525,7 @@ module_state::read_cluster (unsigned snum) if (abstract) ; - else if (DECL_ABSTRACT_P (decl)) + else if (DECL_MAYBE_IN_CHARGE_CDTOR_P (decl)) vec_safe_push (post_load_decls, decl); else { @@ -17947,10 +17947,11 @@ post_load_processing () dump () && dump ("Post-load processing of %N", decl); - gcc_checking_assert (DECL_ABSTRACT_P (decl)); + gcc_checking_assert (DECL_MAYBE_IN_CHARGE_CDTOR_P (decl)); /* Cloning can cause loading -- specifically operator delete for the deleting dtor. */ - maybe_clone_body (decl); + if (!TREE_ASM_WRITTEN (decl) && maybe_clone_body (decl)) + TREE_ASM_WRITTEN (decl) = 1; } cfun = old_cfun; diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 5ab2076b673..f7ae8e68dcf 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -5122,7 +5122,7 @@ expand_or_defer_fn_1 (tree fn) demand, so we also need to keep the body. Otherwise we don't need it anymore. */ if (!DECL_DECLARED_CONSTEXPR_P (fn) - && !(modules_p () && vague_linkage_p (fn))) + && !(module_maybe_has_cmi_p () && vague_linkage_p (fn))) DECL_SAVED_TREE (fn) = NULL_TREE; return false; } diff --git a/gcc/testsuite/g++.dg/modules/virt-6_a.C b/gcc/testsuite/g++.dg/modules/virt-6_a.C new file mode 100644 index 00000000000..68e466ace3f --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/virt-6_a.C @@ -0,0 +1,13 @@ +// PR c++/115007 +// { dg-additional-options "-fmodules-ts -Wno-global-module" } +// { dg-module-cmi M:a } + +module; +struct S { + virtual ~S() = default; + virtual void f() = 0; +}; +module M:a; +extern S* p; +template void format(T) { p->~S(); } +template void format(int); diff --git a/gcc/testsuite/g++.dg/modules/virt-6_b.C b/gcc/testsuite/g++.dg/modules/virt-6_b.C new file mode 100644 index 00000000000..c53f5fac742 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/virt-6_b.C @@ -0,0 +1,6 @@ +// PR c++/115007 +// { dg-additional-options "-fmodules-ts" } +// { dg-module-cmi M } + +export module M; +import :a; From patchwork Tue Aug 20 23:41:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathaniel Shead X-Patchwork-Id: 1974618 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=SRwRtlzE; 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 4WpQwp0VTxz1yXf for ; Wed, 21 Aug 2024 09:42:02 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E31D8387089A for ; Tue, 20 Aug 2024 23:41:59 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by sourceware.org (Postfix) with ESMTPS id A1EFF3858433 for ; Tue, 20 Aug 2024 23:41:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A1EFF3858433 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 A1EFF3858433 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::62d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724197298; cv=none; b=BMxcu/6ftDLXdX4KxGJKvA6QjVm/gyfxHxg9RRGFBbpYKcJ7yQn93rbEspkQYVLcGRzRpkbkieNlKtdNDmDzkdquyCRI+QUv/5G8D9AdUOfCgbEYeMRNsLRio1leSQXFTPpYEtGlyAj2ILe5mCso0uqsnga5yUBXaSZYHOfG374= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724197298; c=relaxed/simple; bh=D0ZBvcwaFoXZ87FnZKzNzW8gNas6EYAHZI84jLY2cFQ=; h=DKIM-Signature:Message-ID:Date:From:To:Subject:MIME-Version; b=Sgc2IjzVkXCal8MCbK2EIlFQLfsM3FZn6fcRtd7xbWUCbLL9MPALHONDlHuMdlHwS3ZYBJ2PoPJcottjAO8f+N7z8JY24wnVDahGx36Ig22mniCYEHMusGBGFB8Ffp0LpZ1sGTZAeqAy7ovWGBNSY5zvbkRDGftaQpKLgfFjFK0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-201e2ebed48so145605ad.0 for ; Tue, 20 Aug 2024 16:41:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724197295; x=1724802095; 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=1aTE6MzzCVLdIuu7rPfm2K7/dPlFz7SIaN9x13ctw2Y=; b=SRwRtlzE2hmcY1wRtaP4Dfx0bma0gQ1XPDvdUpO19konE1Ed+GOK95dNioA4mlSmto jOb7lUPmfHDEz3xVPZwoG/m/1DkdqqLh3a6r6mbkL5A7mBsmvPC50uqQC8yNf58099VU t9CXqsvgSWBMOTDKZjjfMZ3m7GphwNMGKG9UcgCUeeGxMYgAl5G5Q+LPbj2dh9279rlh Ptdlb97cAfgQhJpK910wDTmluf9Dx4ERDB5ibsmEZ5wyBLpORYcTikiYNNDzodx+i5fX pyStB3F6Fu7UviTcrCLKd1/giPwhqQdCKflg6nbQzyPnINHV0/08BMrnbvt+WmXJR4aL gPGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724197295; x=1724802095; 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=1aTE6MzzCVLdIuu7rPfm2K7/dPlFz7SIaN9x13ctw2Y=; b=WXIPFWX4UicSZQpwo49P/5MSI6gCHF+Y7HXeQOzY4e8Xzp57Zsu/YDRq63fJJrqruW DhmctGZMFCr34qtLvPlut1M02yX5TONPp56vQXqENzg/lRHMMgHnqawog5diR5NFLm58 /0Oh3jVvL6/227u/eV0xpVkWqtwICFQJ6VpNg4EfUOjYAemI0oXSFlv172pLyyKJnbr8 soCW7bWd47XRkeBehMrVMKwpQpw9zo+bQPo0MnRv+60/F0tULjq0zdu2tz2mn9SjBli3 22XXXsuT/DMcFnsQ8z2e+vxLZSNHHARdIvnA6ejLibnK/J9FOwOcKaOzt/42I9FD7zHk iPCg== X-Gm-Message-State: AOJu0YwWyhpzhqSkU6G/Bl6k5rTNqmSn/VsDZe1GNXwUuCqoJ8DF/znk rd7c5cEEYPhlTiQwl5qwt69BEb4t9bEIA+nABIugaTi4K6x404zQyL0Nog== X-Google-Smtp-Source: AGHT+IGQ9FOf8vKDo1xknIMb261/y4JzOhHNLIsCypNmRw/JvuwKDnlOIMhgCi/oyFsqOASvcHUluA== X-Received: by 2002:a17:902:ea09:b0:202:2af7:b50b with SMTP id d9443c01a7336-20367e71209mr3482605ad.5.1724197295472; Tue, 20 Aug 2024 16:41:35 -0700 (PDT) Received: from Thaum. (110-175-236-231.static.tpgi.com.au. [110.175.236.231]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-201f02fb7afsm82862145ad.5.2024.08.20.16.41.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Aug 2024 16:41:35 -0700 (PDT) Message-ID: <66c529af.170a0220.62c84.d316@mx.google.com> X-Google-Original-Message-ID: Date: Wed, 21 Aug 2024 09:41:31 +1000 From: Nathaniel Shead To: gcc-patches@gcc.gnu.org Cc: Jason Merrill , Nathan Sidwell Subject: [PATCH 3/3] c++/modules: Support decloned cdtors References: <66c52908.170a0220.2c87fb.d675@mx.google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <66c52908.170a0220.2c87fb.d675@mx.google.com> X-Spam-Status: No, score=-12.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 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 -- When compiling with '-fdeclone-ctor-dtor' (enabled by default with -Os), we run into issues where we don't correctly emit the underlying functions. We also need to ensure that COMDAT constructors are marked as such before 'maybe_clone_body' attempts to propagate COMDAT groups to the new thunks. gcc/cp/ChangeLog: * module.cc (post_load_processing): Mark COMDAT as needed, emit declarations if maybe_clone_body fails. gcc/testsuite/ChangeLog: * g++.dg/modules/clone-2_a.C: New test. * g++.dg/modules/clone-2_b.C: New test. * g++.dg/modules/clone-3_a.C: New test. * g++.dg/modules/clone-3_b.C: New test. Signed-off-by: Nathaniel Shead --- gcc/cp/module.cc | 20 ++++++++++++++++---- gcc/testsuite/g++.dg/modules/clone-2_a.C | 7 +++++++ gcc/testsuite/g++.dg/modules/clone-2_b.C | 5 +++++ gcc/testsuite/g++.dg/modules/clone-3_a.C | 9 +++++++++ gcc/testsuite/g++.dg/modules/clone-3_b.C | 8 ++++++++ 5 files changed, 45 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/g++.dg/modules/clone-2_a.C create mode 100644 gcc/testsuite/g++.dg/modules/clone-2_b.C create mode 100644 gcc/testsuite/g++.dg/modules/clone-3_a.C create mode 100644 gcc/testsuite/g++.dg/modules/clone-3_b.C diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc index 5cd4f313933..9a9c0fdfe81 100644 --- a/gcc/cp/module.cc +++ b/gcc/cp/module.cc @@ -17948,10 +17948,22 @@ post_load_processing () dump () && dump ("Post-load processing of %N", decl); gcc_checking_assert (DECL_MAYBE_IN_CHARGE_CDTOR_P (decl)); - /* Cloning can cause loading -- specifically operator delete for - the deleting dtor. */ - if (!TREE_ASM_WRITTEN (decl) && maybe_clone_body (decl)) - TREE_ASM_WRITTEN (decl) = 1; + + if (DECL_COMDAT (decl)) + comdat_linkage (decl); + if (!TREE_ASM_WRITTEN (decl)) + { + /* Cloning can cause loading -- specifically operator delete for + the deleting dtor. */ + if (maybe_clone_body (decl)) + TREE_ASM_WRITTEN (decl) = 1; + else + { + /* We didn't clone the cdtor, make sure we emit it. */ + note_vague_linkage_fn (decl); + cgraph_node::finalize_function (decl, true); + } + } } cfun = old_cfun; diff --git a/gcc/testsuite/g++.dg/modules/clone-2_a.C b/gcc/testsuite/g++.dg/modules/clone-2_a.C new file mode 100644 index 00000000000..47e21581fdc --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/clone-2_a.C @@ -0,0 +1,7 @@ +// { dg-additional-options "-fmodules-ts -fdeclone-ctor-dtor" } +// { dg-module-cmi M } + +export module M; +export struct S { + inline S(int) {} +}; diff --git a/gcc/testsuite/g++.dg/modules/clone-2_b.C b/gcc/testsuite/g++.dg/modules/clone-2_b.C new file mode 100644 index 00000000000..80c1e149518 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/clone-2_b.C @@ -0,0 +1,5 @@ +// { dg-additional-options "-fmodules-ts -fdeclone-ctor-dtor" } + +import M; + +S s(0); diff --git a/gcc/testsuite/g++.dg/modules/clone-3_a.C b/gcc/testsuite/g++.dg/modules/clone-3_a.C new file mode 100644 index 00000000000..87de746f5c2 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/clone-3_a.C @@ -0,0 +1,9 @@ +// { dg-additional-options "-fmodules-ts -fdeclone-ctor-dtor" } +// { dg-module-cmi M } + +export module M; + +struct A {}; +export struct B : virtual A { + inline B (int) {} +}; diff --git a/gcc/testsuite/g++.dg/modules/clone-3_b.C b/gcc/testsuite/g++.dg/modules/clone-3_b.C new file mode 100644 index 00000000000..23c9ac4a804 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/clone-3_b.C @@ -0,0 +1,8 @@ +// { dg-module-do link } +// { dg-additional-options "-fmodules-ts -fdeclone-ctor-dtor" } + +import M; + +int main() { + B b(0); +}