public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Chung-Lin Tang <cltang@codesourcery.com>
Cc: gcc-patches <gcc-patches@gcc.gnu.org>
Subject: [committed] openmp: Fix handling of target constructs in static member functions [PR106829]
Date: Wed, 7 Sep 2022 09:04:19 +0200	[thread overview]
Message-ID: <YxhCcwYSkpW+FJvg@tucnak> (raw)
In-Reply-To: <d24da62a-5135-5945-b985-134cc3274859@codesourcery.com>

On Tue, Nov 16, 2021 at 08:43:27PM +0800, Chung-Lin Tang wrote:
> 2021-11-16  Chung-Lin Tang  <cltang@codesourcery.com>
> 
> 	PR middle-end/92120
> 
> gcc/cp/ChangeLog:
> 
> 	* semantics.c (handle_omp_array_sections_1): Add handling to create
...
> 	(finish_omp_target_clauses): New function.

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

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux,
committed to trunk, queued for 12.3 backport.

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.

--- gcc/cp/semantics.cc.jj	2022-09-03 09:41:34.892005463 +0200
+++ gcc/cp/semantics.cc	2022-09-06 15:00:33.253199294 +0200
@@ -9555,16 +9555,15 @@ finish_omp_target_clauses (location_t lo
 {
   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))
     {
--- gcc/testsuite/g++.dg/gomp/pr106829.C.jj	2022-09-06 15:03:44.305635408 +0200
+++ gcc/testsuite/g++.dg/gomp/pr106829.C	2022-09-06 15:03:12.987055704 +0200
@@ -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;
+}


	Jakub


      parent reply	other threads:[~2022-09-07  7:04 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-18 14:25 [PATCH, OpenMP 5.0] Improve OpenMP target support for C++ [PR92120 v4] Chung-Lin Tang
2021-06-24 13:15 ` Jakub Jelinek
2021-11-16 12:43   ` [PATCH, v5, OpenMP 5.0] Improve OpenMP target support for C++ [PR92120 v5] Chung-Lin Tang
2021-12-03 16:47     ` Jakub Jelinek
2021-12-09 16:41       ` Chung-Lin Tang
2022-09-07  7:04     ` Jakub Jelinek [this message]

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=YxhCcwYSkpW+FJvg@tucnak \
    --to=jakub@redhat.com \
    --cc=cltang@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).