]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Allow static constexpr fields in mappable types for C++
authorChung-Lin Tang <cltang@codesourcery.com>
Wed, 3 Mar 2021 14:39:10 +0000 (22:39 +0800)
committerKwok Cheung Yeung <kcy@codesourcery.com>
Tue, 21 Jun 2022 13:11:33 +0000 (14:11 +0100)
This patch is a merge of:
https://gcc.gnu.org/legacy-ml/gcc-patches/2020-01/msg01246.html

Static members in general disqualify a C++ class from being target mappable,
but static constexprs are inline optimized away, so should not interfere.

OpenMP 5.0 in general lifts the static member limitation, so this
patch will probably further adjusted later.

2021-03-03  Chung-Lin Tang  <cltang@codesourcery.com>

gcc/cp/ChangeLog:

* decl2.cc (cp_omp_mappable_type_1): Allow fields with
DECL_DECLARED_CONSTEXPR_P to be mapped.

gcc/testsuite/ChangeLog:

* g++.dg/goacc/static-constexpr-1.C: New test.
* g++.dg/gomp/static-constexpr-1.C: New test.

gcc/cp/ChangeLog.omp
gcc/cp/decl2.cc
gcc/testsuite/ChangeLog.omp
gcc/testsuite/g++.dg/goacc/static-constexpr-1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/gomp/static-constexpr-1.C [new file with mode: 0644]

index f37510eb0fa9886c1ce96c0c7284b821ca4a539d..efda4eddf14a9feb25969dd81d21e8cae2e3fafd 100644 (file)
@@ -1,3 +1,8 @@
+2021-03-03  Chung-Lin Tang  <cltang@codesourcery.com>
+
+       * decl2.cc (cp_omp_mappable_type_1): Allow fields with
+       DECL_DECLARED_CONSTEXPR_P to be mapped.
+
 2021-02-02  Chung-Lin Tang  <cltang@codesourcery.com>
 
        * parser.cc (cp_parser_simple_declaration): Set
index d2b29208ed5c5da1331252ba93ba0fd44be90af3..d947c829756c806539fcd7b91535066e1483f3e1 100644 (file)
@@ -1577,7 +1577,10 @@ cp_omp_mappable_type_1 (tree type, bool notes)
     {
       tree field;
       for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
-       if (VAR_P (field))
+       if (VAR_P (field)
+           /* Fields that are 'static constexpr' can be folded away at compile
+              time, thus does not interfere with mapping.  */
+           && !DECL_DECLARED_CONSTEXPR_P (field))
          {
            if (notes)
              inform (DECL_SOURCE_LOCATION (field),
index fd15e7aa7fbd04c736e9c36aa80db8385b01d44f..5365d8950cd1e62d5a50107dbda5d46876413d63 100644 (file)
@@ -1,3 +1,8 @@
+2021-03-03  Chung-Lin Tang  <cltang@codesourcery.com>
+
+       * g++.dg/goacc/static-constexpr-1.C: New test.
+       * g++.dg/gomp/static-constexpr-1.C: New test.
+
 2021-02-02  Chung-Lin Tang  <cltang@codesourcery.com>
 
        * c-c++-common/gomp/requires-4.c: Remove prune of "not supported yet".
diff --git a/gcc/testsuite/g++.dg/goacc/static-constexpr-1.C b/gcc/testsuite/g++.dg/goacc/static-constexpr-1.C
new file mode 100644 (file)
index 0000000..edf5f1a
--- /dev/null
@@ -0,0 +1,17 @@
+// { dg-do compile }
+// { dg-require-effective-target c++11 }
+
+/* Test that static constexpr members do not interfere with offloading.  */
+struct rec
+{
+  static constexpr int x = 1;
+  int y, z;
+};
+
+void foo (rec& r)
+{
+  #pragma acc parallel copy(r)
+  {
+    r.y = r.y = r.x;
+  }
+}
diff --git a/gcc/testsuite/g++.dg/gomp/static-constexpr-1.C b/gcc/testsuite/g++.dg/gomp/static-constexpr-1.C
new file mode 100644 (file)
index 0000000..39eee92
--- /dev/null
@@ -0,0 +1,17 @@
+// { dg-do compile }
+// { dg-require-effective-target c++11 }
+
+/* Test that static constexpr members do not interfere with offloading.  */
+struct rec
+{
+  static constexpr int x = 1;
+  int y, z;
+};
+
+void foo (rec& r)
+{
+  #pragma omp target map(r)
+  {
+    r.y = r.y = r.x;
+  }
+}