public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Paul-Antoine Arras <Paul-Antoine_Arras@mentor.com>
To: <gcc-patches@gcc.gnu.org>
Cc: <ams@codesourcery.com>
Subject: [OG12][PATCH] openmp: Fix handling of target constructs in static member
Date: Tue, 13 Sep 2022 13:03:35 +0200	[thread overview]
Message-ID: <62eb3792-62f6-7ebf-aa41-01d03287b573@mentor.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 230 bytes --]

Hello,

This patch intends to backport e90af965e5c by Jakub Jelinek to 
devel/omp/gcc-12.
The original patch was described here: 
https://gcc.gnu.org/pipermail/gcc-patches/2022-September/601189.html

Thanks,
-- 
Paul-Antoine Arras

[-- Attachment #2: 0001-openmp-Fix-handling-of-target-constructs-in-static-m.patch --]
[-- Type: text/plain, Size: 3671 bytes --]

From c1fb6ff897d0b929807d52cf52d4894e252e7d96 Mon Sep 17 00:00:00 2001
From: Jakub Jelinek <jakub@redhat.com>
Date: Wed, 7 Sep 2022 08:54:13 +0200
Subject: [PATCH] openmp: Fix handling of target constructs in static member
 functions [PR106829]

Just calling current_nonlambda_class_type in static member functions returns
non-NULL, but something that isn't *this and if unlucky can match part of the
IL and can be added to target clauses.
      if (DECL_NONSTATIC_MEMBER_P (decl)
          && current_class_ptr)
is a guard used elsewhere (in check_accessibility_of_qualified_id).

2022-09-07  Jakub Jelinek  <jakub@redhat.com>

	PR c++/106829
	* semantics.cc (finish_omp_target_clauses): If current_function_decl
	isn't a nonstatic member function, don't set data.current_object to
	non-NULL.

	* g++.dg/gomp/pr106829.C: New test.

(cherry picked from commit e90af965e5c858ba02c0cdfbac35d0a19da1c2f6)
---
 gcc/cp/ChangeLog.omp                 | 10 ++++++++++
 gcc/cp/semantics.cc                  | 17 ++++++++---------
 gcc/testsuite/ChangeLog.omp          |  8 ++++++++
 gcc/testsuite/g++.dg/gomp/pr106829.C | 15 +++++++++++++++
 4 files changed, 41 insertions(+), 9 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/gomp/pr106829.C

diff --git gcc/cp/ChangeLog.omp gcc/cp/ChangeLog.omp
index 35504f4c92b..c3214f31252 100644
--- gcc/cp/ChangeLog.omp
+++ gcc/cp/ChangeLog.omp
@@ -1,3 +1,13 @@
+2022-09-09  Paul-Antoine Arras  <pa@codesourcery.com>
+
+	Backport from mainline:
+	2022-09-07  Jakub Jelinek  <jakub@redhat.com>
+
+	PR c++/106829
+	* semantics.cc (finish_omp_target_clauses): If current_function_decl
+	isn't a nonstatic member function, don't set data.current_object to
+	non-NULL.
+
 2022-09-07  Tobias Burnus  <tobias@codesourcery.com>
 
 	Backport from mainline:
diff --git gcc/cp/semantics.cc gcc/cp/semantics.cc
index 7717a820f0d..dad04dc4757 100644
--- gcc/cp/semantics.cc
+++ gcc/cp/semantics.cc
@@ -9727,16 +9727,15 @@ finish_omp_target_clauses (location_t loc, tree body, tree *clauses_ptr)
 {
   omp_target_walk_data data;
   data.this_expr_accessed = false;
+  data.current_object = NULL_TREE;
 
-  tree ct = current_nonlambda_class_type ();
-  if (ct)
-    {
-      tree object = maybe_dummy_object (ct, NULL);
-      object = maybe_resolve_dummy (object, true);
-      data.current_object = object;
-    }
-  else
-    data.current_object = NULL_TREE;
+  if (DECL_NONSTATIC_MEMBER_P (current_function_decl) && current_class_ptr)
+    if (tree ct = current_nonlambda_class_type ())
+      {
+	tree object = maybe_dummy_object (ct, NULL);
+	object = maybe_resolve_dummy (object, true);
+	data.current_object = object;
+      }
 
   if (DECL_LAMBDA_FUNCTION_P (current_function_decl))
     {
diff --git gcc/testsuite/ChangeLog.omp gcc/testsuite/ChangeLog.omp
index ed42b20b099..9ca4d936ff5 100644
--- gcc/testsuite/ChangeLog.omp
+++ gcc/testsuite/ChangeLog.omp
@@ -1,3 +1,11 @@
+2022-09-09  Paul-Antoine Arras  <pa@codesourcery.com>
+
+	Backport from mainline:
+	2022-09-07  Jakub Jelinek  <jakub@redhat.com>
+
+	PR c++/106829
+	* g++.dg/gomp/pr106829.C: New test.
+
 2022-09-07  Tobias Burnus  <tobias@codesourcery.com>
 
 	Backport from mainline:
diff --git gcc/testsuite/g++.dg/gomp/pr106829.C gcc/testsuite/g++.dg/gomp/pr106829.C
new file mode 100644
index 00000000000..0295efb88ee
--- /dev/null
+++ gcc/testsuite/g++.dg/gomp/pr106829.C
@@ -0,0 +1,15 @@
+// PR c++/106829
+
+namespace std
+{
+  template <typename> class complex;
+  template <> struct complex<double> { complex (double); _Complex double d; };
+}
+struct S { void static foo (); };
+
+void
+S::foo ()
+{
+#pragma omp target
+  std::complex<double> c = 0.0;
+}
-- 
2.31.1


             reply	other threads:[~2022-09-13 11:03 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-13 11:03 Paul-Antoine Arras [this message]
2022-09-13 11:36 ` Andrew Stubbs

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=62eb3792-62f6-7ebf-aa41-01d03287b573@mentor.com \
    --to=paul-antoine_arras@mentor.com \
    --cc=ams@codesourcery.com \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).