summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Burnus <tobias@codesourcery.com>2022-02-10 18:57:37 +0100
committerTobias Burnus <tobias@codesourcery.com>2022-03-23 08:30:42 +0100
commit1073e7691804f43993cd9f8446f8ebda9004ad98 (patch)
tree895754b06bcbaf66c4e29a8f1f3c62da3e16c1e0
parent8ab67f22c79037dc83fdec2412a0ad033e327e48 (diff)
OpenMP/C++: Permit mapping classes with virtual members [PR102204]
PR c++/102204 gcc/cp/ChangeLog: * decl2.c (cp_omp_mappable_type_1): Remove check for virtual members as those are permitted since OpenMP 5.0. 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. (cherry picked from commit c22f3fb780775b91548e32937a3ce1095a7c72a3)
-rw-r--r--gcc/cp/decl2.c8
-rw-r--r--gcc/testsuite/g++.dg/gomp/unmappable-1.C2
-rw-r--r--libgomp/testsuite/libgomp.c++/target-virtual-1.C50
3 files changed, 51 insertions, 9 deletions
diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c
index ccb98fdc193..3503e544419 100644
--- a/gcc/cp/decl2.c
+++ b/gcc/cp/decl2.c
@@ -1448,14 +1448,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;
- }
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 aba8497003f..1532b9c73f1 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;
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;
+}