]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
openmp: Fix handling of target constructs in static member functions [PR106829]
authorJakub Jelinek <jakub@redhat.com>
Wed, 7 Sep 2022 06:54:13 +0000 (08:54 +0200)
committerAndrew Stubbs <ams@codesourcery.com>
Tue, 13 Sep 2022 11:25:26 +0000 (12:25 +0100)
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
gcc/cp/semantics.cc
gcc/testsuite/ChangeLog.omp
gcc/testsuite/g++.dg/gomp/pr106829.C [new file with mode: 0644]

index 35504f4c92b269daf0acec2b7a7af0191f24ef74..c3214f312524eb0c7d74372e494e65bb5313a1a9 100644 (file)
@@ -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:
index 7717a820f0dbcfdf1de0a9fc31ff1ebb0518b25b..dad04dc4757041f6bfe50524420b06fa6918c1ac 100644 (file)
@@ -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))
     {
index 74b36e20c5a3649bc72d2562cc90274a380cf9e7..e0c8c1386208094414718307a863eb5dcd472289 100644 (file)
@@ -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-09  Tobias Burnus  <tobias@codesourcery.com>
 
        Backport from mainline:
diff --git a/gcc/testsuite/g++.dg/gomp/pr106829.C b/gcc/testsuite/g++.dg/gomp/pr106829.C
new file mode 100644 (file)
index 0000000..0295efb
--- /dev/null
@@ -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;
+}