public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/omp/gcc-12] Allow static constexpr fields in mappable types for C++
@ 2022-06-29 14:39 Kwok Yeung
  0 siblings, 0 replies; only message in thread
From: Kwok Yeung @ 2022-06-29 14:39 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:1f4ee53c2ea6ad4a91550d3e15f80cc7df24efa2

commit 1f4ee53c2ea6ad4a91550d3e15f80cc7df24efa2
Author: Chung-Lin Tang <cltang@codesourcery.com>
Date:   Wed Mar 3 22:39:10 2021 +0800

    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.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.

Diff:
---
 gcc/cp/ChangeLog.omp                            |  5 +++++
 gcc/cp/decl2.cc                                 |  5 ++++-
 gcc/testsuite/ChangeLog.omp                     |  5 +++++
 gcc/testsuite/g++.dg/goacc/static-constexpr-1.C | 17 +++++++++++++++++
 gcc/testsuite/g++.dg/gomp/static-constexpr-1.C  | 17 +++++++++++++++++
 5 files changed, 48 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/ChangeLog.omp b/gcc/cp/ChangeLog.omp
index f37510eb0fa..efda4eddf14 100644
--- a/gcc/cp/ChangeLog.omp
+++ b/gcc/cp/ChangeLog.omp
@@ -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
diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc
index d2b29208ed5..d947c829756 100644
--- a/gcc/cp/decl2.cc
+++ b/gcc/cp/decl2.cc
@@ -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),
diff --git a/gcc/testsuite/ChangeLog.omp b/gcc/testsuite/ChangeLog.omp
index fd15e7aa7fb..5365d8950cd 100644
--- a/gcc/testsuite/ChangeLog.omp
+++ b/gcc/testsuite/ChangeLog.omp
@@ -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
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;
+  }
+}


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-06-29 14:39 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-29 14:39 [gcc/devel/omp/gcc-12] Allow static constexpr fields in mappable types for C++ Kwok Yeung

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).