From patchwork Thu Feb 10 17:35:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 1591268 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JvkRX4G74z9sFq for ; Fri, 11 Feb 2022 04:35:35 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 616B13858021 for ; Thu, 10 Feb 2022 17:35:32 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from esa1.mentor.iphmx.com (esa1.mentor.iphmx.com [68.232.129.153]) by sourceware.org (Postfix) with ESMTPS id BC5783858D1E for ; Thu, 10 Feb 2022 17:35:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org BC5783858D1E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com IronPort-SDR: Ia2DEV3VL+N696f9SG5ZSzafeJ9i48QTUaX4nErKaQHQH4L1Wamz7WgPZUZClLD/WiSfW9uuZD 5ZcWl1Wf9enZMYBlxnNTsmZtj8wOb4JCIil1ZhCwpzdX+CVyi0QDTB/UWLCP6w1F4KsCGUaDGe NMHoapao9DEc7SMUF4E3g38AVr/UdoDYU021s3HQKpydmL/oxhP9HF9t9kUEkH3fXmCNvSOEad v6JN7Hg7l06G3vh0Ooe8D/Ulpky/I6Y3Yg7sS3bUkzlSbPWv0GMUmILfSUWAu+fiRHGOQBfYJl GGOxl6JkRQgXRGq4CUmqQgu7 X-IronPort-AV: E=Sophos;i="5.88,359,1635235200"; d="diff'?scan'208";a="74393549" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa1.mentor.iphmx.com with ESMTP; 10 Feb 2022 09:35:18 -0800 IronPort-SDR: 0rnoyMlnsaihqzV3ssS2mBeelerav2E8067MTmxpQHqA1l3eMytj7Kmihdv8WpW9vcT5A+gVdX fK7uvdBSVwQpeYxpHRIJcGnPNmV2yFSlcy0KeqtWNPIDhd0LGqYgnRD0j1/9HUA9X/Jc2beD72 jaqOYcIRYiPx8CPOOq7/vW0FTkj7oFaHZ81BGL055HiElxbCsxNzAi7tgOhmE2QHQpxSkqQ6eC CRy+QN8RIbUXWCQl7xz3DuxSKrtmn0miBJQPPmBmzye+heIRmh73k86NdfdseFUMvvXOM0JuoM TRY= Message-ID: <99876870-db81-c62b-619e-bb748ed69c27@codesourcery.com> Date: Thu, 10 Feb 2022 18:35:05 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.6.0 Content-Language: en-US To: gcc-patches , Jakub Jelinek From: Tobias Burnus Subject: [Patch] OpenMP/C++: Permit mapping classes with virtual members [PR102204] X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: SVR-IES-MBX-08.mgc.mentorg.com (139.181.222.8) To svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 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 Sender: "Gcc-patches" This patch removes for C++ the OpenMP 4.5 requirement that a class may not be mapped if there are virtual members. It does not do anything beyond and, as RTTI is not accessible (→ OpenMP 5.2) and restrictions exists on using virtual functions (5.0/5.2), that seems to be fine for now. OK? (For GCC 13, I assume) Tobias PS: OpenMP 4.5 had: "A mappable type cannot contain virtual members." OpenMP 5.0: "The effect of invoking a virtual member function of an object on a device other than the device on which the object was constructed is implementation defined." OpenMP 5.2: "• The run-time type information (RTTI) of an object can only be accessed from the device on which it was constructed. • Invoking a virtual member function of an object on a device other than the device on which the object was constructed results in unspecified behavior, unless the object is accessible and was constructed on the host device. • If an object of polymorphic class type is destructed, virtual member functions of any previously existing corresponding objects in other device data environments must not be invoked." ----------------- Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955 OpenMP/C++: Permit mapping classes with virtual members [PR102204] PR C++/102204 gcc/cp/ChangeLog: * decl2.cc (cp_omp_mappable_type_1): libgomp/ChangeLog: * testsuite/libgomp.c++/target-virtual-1.C: New test. gcc/testsuite/ChangeLog: * g++.dg/gomp/unmappable-1.C: Remove previously expected dg-message. gcc/cp/decl2.cc | 8 ---- gcc/testsuite/g++.dg/gomp/unmappable-1.C | 2 +- libgomp/testsuite/libgomp.c++/target-virtual-1.C | 50 ++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 9 deletions(-) diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc index 78908339989..c6bfcfe631a 100644 --- a/gcc/cp/decl2.cc +++ b/gcc/cp/decl2.cc @@ -1540,14 +1540,6 @@ cp_omp_mappable_type_1 (tree type, bool notes) /* Arrays have mappable type if the elements have mappable type. */ while (TREE_CODE (type) == ARRAY_TYPE) type = TREE_TYPE (type); - /* A mappable type cannot contain virtual members. */ - if (CLASS_TYPE_P (type) && CLASSTYPE_VTABLES (type)) - { - if (notes) - inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (type)), - "type %qT with virtual members is not mappable", type); - result = false; - } /* All data members must be non-static. */ if (CLASS_TYPE_P (type)) { diff --git a/gcc/testsuite/g++.dg/gomp/unmappable-1.C b/gcc/testsuite/g++.dg/gomp/unmappable-1.C index d00ccb5ad79..364f884500c 100644 --- a/gcc/testsuite/g++.dg/gomp/unmappable-1.C +++ b/gcc/testsuite/g++.dg/gomp/unmappable-1.C @@ -1,7 +1,7 @@ /* { dg-do compile } */ /* { dg-options "-fopenmp" } */ -class C /* { dg-message "type .C. with virtual members is not mappable" } */ +class C { public: static int static_member; /* { dg-message "static field .C::static_member. is not mappable" } */ diff --git a/libgomp/testsuite/libgomp.c++/target-virtual-1.C b/libgomp/testsuite/libgomp.c++/target-virtual-1.C new file mode 100644 index 00000000000..a6ac30e7cf0 --- /dev/null +++ b/libgomp/testsuite/libgomp.c++/target-virtual-1.C @@ -0,0 +1,50 @@ +/* { dg-do run } */ +/* Check that classes with virtual member functions works, + when using it as declared type. */ +struct base { + float data [100]; + + base() = default; + virtual ~base() = default; +}; + +struct derived : public base { + int scalar, array[5]; + + derived() = default; + void do_work () + { + int error = 0; + #pragma omp target map (tofrom: this[:1], error) + { + if (scalar != 42 || this->array[0] != 123 || array[4] != 555) + error = 1; + if (data[0] != 333 || data[99] != -3) + error = 1; + this->scalar = 99; + array[0] = 5; + array[4] = -4; + this->data[0] = 11; + this->data[99] = 99; + } + if (error) + __builtin_abort (); + if (data[0] != 11 || data[99] != 99) + __builtin_abort (); + if (scalar != 99 || array[0] != 5 || array[4] != -4) + __builtin_abort (); + } +}; + +int +main () +{ + struct derived x; + x.data[0] = 333; + x.data[99] = -3; + x.scalar = 42; + x.array[0] = 123; + x.array[4] = 555; + x.do_work (); + return 0; +}