From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1534) id E784D385843A; Wed, 21 Dec 2022 18:21:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E784D385843A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1671646902; bh=CpaSSHNSFeihOjsDjrOkAf4kKRa5I8tKSNltFv1HJnQ=; h=From:To:Subject:Date:From; b=LbABQ1mkYz/dwarpjUgIPM6G7NWoJQj7ZFpBE4lSymekZ0oVeJniJ3aaER36yRA2A boDdU4C9Icjhkw0W5+f1mFDEve0ISAVangfKHeSbczXFrbDP706j7ZaS2wO0P5e+D6 Ll65tiIp2Ihf6gDnkXPI/RN4czKh5OIggjd8LnWY= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Tobias Burnus To: gcc-cvs@gcc.gnu.org Subject: [gcc/devel/omp/gcc-12] openmp: Don't try to destruct DECL_OMP_PRIVATIZED_MEMBER vars [PR108180] X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/devel/omp/gcc-12 X-Git-Oldrev: 83f24e7faec7b9c367576c61ac9609a67c357e0b X-Git-Newrev: 656960afd2ce23a9cf4e089c7f4ae0b1e5cd3267 Message-Id: <20221221182142.E784D385843A@sourceware.org> Date: Wed, 21 Dec 2022 18:21:42 +0000 (GMT) List-Id: https://gcc.gnu.org/g:656960afd2ce23a9cf4e089c7f4ae0b1e5cd3267 commit 656960afd2ce23a9cf4e089c7f4ae0b1e5cd3267 Author: Jakub Jelinek Date: Wed Dec 21 18:49:17 2022 +0100 openmp: Don't try to destruct DECL_OMP_PRIVATIZED_MEMBER vars [PR108180] DECL_OMP_PRIVATIZED_MEMBER vars are artificial vars with DECL_VALUE_EXPR of this->field used just during gimplification and omp lowering/expansion to privatize individual fields in methods when needed. As the following testcase shows, when not in templates, they were handled right, but in templates we actually called cp_finish_decl on them and that can result in their destruction, which is obviously undesirable, we should only destruct the privatized copies of them created in omp lowering. Fixed thusly. 2022-12-21 Jakub Jelinek PR c++/108180 * pt.cc (tsubst_expr): Don't call cp_finish_decl on DECL_OMP_PRIVATIZED_MEMBER vars. * testsuite/libgomp.c++/pr108180.C: New test. (cherry picked from commit 1119902b6c7c1c50123ed85ec1def8be4772d68c) Diff: --- gcc/cp/ChangeLog.omp | 9 ++++++ gcc/cp/pt.cc | 5 +++ gcc/testsuite/ChangeLog.omp | 8 +++++ libgomp/testsuite/libgomp.c++/pr108180.C | 55 ++++++++++++++++++++++++++++++++ 4 files changed, 77 insertions(+) diff --git a/gcc/cp/ChangeLog.omp b/gcc/cp/ChangeLog.omp index 1899bde8c88..2652871ea21 100644 --- a/gcc/cp/ChangeLog.omp +++ b/gcc/cp/ChangeLog.omp @@ -1,3 +1,12 @@ +2022-12-21 Tobias Burnus + + Backport from mainline: + 2022-12-21 Jakub Jelinek + + PR c++/108180 + * pt.cc (tsubst_expr): Don't call cp_finish_decl on + DECL_OMP_PRIVATIZED_MEMBER vars. + 2022-10-28 Tobias Burnus Backport from mainline: diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 36713ca5420..a7ff31d8679 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -18719,6 +18719,11 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl, tree asmspec_tree = NULL_TREE; maybe_push_decl (decl); + if (VAR_P (decl) + && DECL_LANG_SPECIFIC (decl) + && DECL_OMP_PRIVATIZED_MEMBER (decl)) + break; + if (VAR_P (decl) && DECL_DECOMPOSITION_P (decl) && TREE_TYPE (pattern_decl) != error_mark_node) diff --git a/gcc/testsuite/ChangeLog.omp b/gcc/testsuite/ChangeLog.omp index 1c53c2fc908..7475f6d597f 100644 --- a/gcc/testsuite/ChangeLog.omp +++ b/gcc/testsuite/ChangeLog.omp @@ -1,3 +1,11 @@ +2022-12-21 Tobias Burnus + + Backport from mainline: + 2022-12-21 Jakub Jelinek + + PR c++/108180 + * testsuite/libgomp.c++/pr108180.C: New test. + 2022-12-21 Tobias Burnus Backported from master: diff --git a/libgomp/testsuite/libgomp.c++/pr108180.C b/libgomp/testsuite/libgomp.c++/pr108180.C new file mode 100644 index 00000000000..452910cebeb --- /dev/null +++ b/libgomp/testsuite/libgomp.c++/pr108180.C @@ -0,0 +1,55 @@ +// PR c++/108180 +// { dg-do run } + +struct A { + A () { ++a; } + A (A &&) = delete; + A (const A &) { ++a; } + A &operator= (const A &) = delete; + A &operator= (A &&) = delete; + ~A () { --a; } + static int a; +}; +int A::a = 0; + +struct B { + A a; + template + int + foo () + { + int res = 0; + #pragma omp parallel for if(false) firstprivate(a) + for (int i = 0; i < 64; ++i) + res += i; + return res; + } + int + bar () + { + int res = 0; + #pragma omp parallel for if(false) firstprivate(a) + for (int i = 0; i < 64; ++i) + res += i; + return res; + } +}; + +int +main () +{ + { + B b; + if (b.foo<0> () != 2016) + __builtin_abort (); + } + if (A::a != 0) + __builtin_abort (); + { + B b; + if (b.bar () != 2016) + __builtin_abort (); + } + if (A::a != 0) + __builtin_abort (); +}