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:} } }