* [Patch] OpenMP/C++: Permit mapping classes with virtual members [PR102204]
@ 2022-02-10 17:35 Tobias Burnus
2022-02-10 17:38 ` Jakub Jelinek
0 siblings, 1 reply; 2+ messages in thread
From: Tobias Burnus @ 2022-02-10 17:35 UTC (permalink / raw)
To: gcc-patches, Jakub Jelinek
[-- Attachment #1: Type: text/plain, Size: 1457 bytes --]
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
[-- Attachment #2: virtual-func-map.diff --]
[-- Type: text/x-patch, Size: 3068 bytes --]
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;
+}
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [Patch] OpenMP/C++: Permit mapping classes with virtual members [PR102204]
2022-02-10 17:35 [Patch] OpenMP/C++: Permit mapping classes with virtual members [PR102204] Tobias Burnus
@ 2022-02-10 17:38 ` Jakub Jelinek
0 siblings, 0 replies; 2+ messages in thread
From: Jakub Jelinek @ 2022-02-10 17:38 UTC (permalink / raw)
To: Tobias Burnus; +Cc: gcc-patches
On Thu, Feb 10, 2022 at 06:35:05PM +0100, Tobias Burnus wrote:
> PR C++/102204
> gcc/cp/ChangeLog:
>
> * decl2.cc (cp_omp_mappable_type_1):
Description of the change is missing.
> 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.
Let's do it for GCC 12 already. Ok with the ChangeLog fixed up.
Jakub
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-02-10 17:38 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-10 17:35 [Patch] OpenMP/C++: Permit mapping classes with virtual members [PR102204] Tobias Burnus
2022-02-10 17:38 ` Jakub Jelinek
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).