From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1461) id D5E153857355; Tue, 13 Sep 2022 11:27:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D5E153857355 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663068477; bh=IbpqQXfWQjQg6QqpK6PGbm4mT+XHcG2uDW1APuGkg4M=; h=From:To:Subject:Date:From; b=k9fAiou5XvQ287nF8zSPUXAO3aMcWP0k8ipOX3IE2cxRMjN13Cvcr7yfs0TOiK0t7 IUuBs8xMBA2rsaxmEpj9H494dDsivX3W3gkFU4UXxI7+AONVWfyvXwWfI5RCccDmYi p/p7zL+MNGzstFHpcS0EYjO+kaw/bLKQYnQ5SyIA= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Andrew Stubbs To: gcc-cvs@gcc.gnu.org Subject: [gcc/devel/omp/gcc-12] openmp: Fix handling of target constructs in static member functions [PR106829] X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/devel/omp/gcc-12 X-Git-Oldrev: 0c17135a894dffe99f31fde250da133b38c2888c X-Git-Newrev: 82bfbdca15292ca2ca614c7ec16b8fe10124ddd4 Message-Id: <20220913112757.D5E153857355@sourceware.org> Date: Tue, 13 Sep 2022 11:27:57 +0000 (GMT) List-Id: https://gcc.gnu.org/g:82bfbdca15292ca2ca614c7ec16b8fe10124ddd4 commit 82bfbdca15292ca2ca614c7ec16b8fe10124ddd4 Author: Jakub Jelinek Date: Wed Sep 7 08:54:13 2022 +0200 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 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) Diff: --- 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(-) diff --git a/gcc/cp/ChangeLog.omp b/gcc/cp/ChangeLog.omp index 35504f4c92b..c3214f31252 100644 --- a/gcc/cp/ChangeLog.omp +++ b/gcc/cp/ChangeLog.omp @@ -1,3 +1,13 @@ +2022-09-09 Paul-Antoine Arras + + Backport from mainline: + 2022-09-07 Jakub Jelinek + + 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 Backport from mainline: diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 7717a820f0d..dad04dc4757 100644 --- a/gcc/cp/semantics.cc +++ b/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 a/gcc/testsuite/ChangeLog.omp b/gcc/testsuite/ChangeLog.omp index 74b36e20c5a..e0c8c138620 100644 --- a/gcc/testsuite/ChangeLog.omp +++ b/gcc/testsuite/ChangeLog.omp @@ -1,3 +1,11 @@ +2022-09-09 Paul-Antoine Arras + + Backport from mainline: + 2022-09-07 Jakub Jelinek + + PR c++/106829 + * g++.dg/gomp/pr106829.C: New test. + 2022-09-09 Tobias Burnus 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 index 00000000000..0295efb88ee --- /dev/null +++ b/gcc/testsuite/g++.dg/gomp/pr106829.C @@ -0,0 +1,15 @@ +// PR c++/106829 + +namespace std +{ + template class complex; + template <> struct complex { complex (double); _Complex double d; }; +} +struct S { void static foo (); }; + +void +S::foo () +{ +#pragma omp target + std::complex c = 0.0; +}