diff mbox series

[C++,OG10,OpenACC/OpenMP,committed] Allow static constexpr fields in mappable types

Message ID 0285351a-31d5-a45c-35be-0b21a90d1483@codesourcery.com
State New
Headers show
Series [C++,OG10,OpenACC/OpenMP,committed] Allow static constexpr fields in mappable types | expand

Commit Message

Chung-Lin Tang March 3, 2021, 2:41 p.m. UTC
On 2020/1/21 12:49 AM, Jakub Jelinek wrote:
> The OpenMP 4.5 definition of mappable type for C++ is that
>    - All data members must be non-static.
> among other requirements.  In OpenMP 5.0 that has been removed.
> So, if we follow the 4.5 definition, it shouldn't change, if we follow 5.0
> definition, the whole loop should be dropped, but in no case shall static
> constexpr data members be treated any differently from any other static data
> members.

We have merged the patch as is (only static constexprs) to devel/omp/gcc-10
for now. Its possible that the entire checking loop should be eventually removed
to allow the full 5.0 range, but wondered if things like (automatic) accessibility
of the static members within target regions is an issue to resolve?
For now, I've committed the patch in its current state to OG10.

Re-tested on OG10, and committed with an additional testcase (same for OpenMP)

Chung-Lin

	cp/
	* decl2.c (cp_omp_mappable_type_1): Allow fields with
	DECL_DECLARED_CONSTEXPR_P to be mapped.

	testsuite/
	* g++.dg/goacc/static-constexpr-1.C: New test.
	* g++.dg/gomp/static-constexpr-1.C: New test.
From 1c3f38b30c1db0aef5ccbf6d20fb5fd13785d482 Mon Sep 17 00:00:00 2001
From: Chung-Lin Tang <cltang@codesourcery.com>
Date: Wed, 3 Mar 2021 22:39:10 +0800
Subject: [PATCH] Allow static constexpr fields in mappable types for C++

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.c (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/decl2.c                                  |  5 ++++-
 gcc/testsuite/g++.dg/goacc/static-constexpr-1.C | 17 +++++++++++++++++
 gcc/testsuite/g++.dg/gomp/static-constexpr-1.C  | 17 +++++++++++++++++
 3 files changed, 38 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/goacc/static-constexpr-1.C
 create mode 100644 gcc/testsuite/g++.dg/gomp/static-constexpr-1.C
diff mbox series

Patch

diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c
index 5343ea3b068..872122fe83c 100644
--- a/gcc/cp/decl2.c
+++ b/gcc/cp/decl2.c
@@ -1460,7 +1460,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),
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
index 00000000000..edf5f1a7628
--- /dev/null
+++ b/gcc/testsuite/g++.dg/goacc/static-constexpr-1.C
@@ -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
index 00000000000..39eee92dddd
--- /dev/null
+++ b/gcc/testsuite/g++.dg/gomp/static-constexpr-1.C
@@ -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;
+  }
+}