From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id 7835D385B516; Tue, 2 May 2023 20:13:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7835D385B516 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1683058385; bh=W69iMH3epi7OS16zx/KW/T9s6DQPXvlhOLYf95fcNP4=; h=From:To:Subject:Date:From; b=UCt6qPkL9Rt4vulTEHXZgjYYR8uFiIQgnsNqc7U+SaiXIFtsqQPRecTee1B9HWnUh LXlJ1SJvynHIscL5jTxMbhTFzAchloOHrqJhFQf3/i9FYmWRNAOhBsR8WU4ueT24MH Jl/9YQni+y778Uj0fmGLEJ45aYZJjuN3hswbScio= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jakub Jelinek To: gcc-cvs@gcc.gnu.org Subject: [gcc r11-10693] 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/releases/gcc-11 X-Git-Oldrev: ab03e6bdc590393a36d62cf14fe0280529c933ae X-Git-Newrev: 9eed31b91ce73a9499297bf8ef2c2b7ce4c8d79b Message-Id: <20230502201305.7835D385B516@sourceware.org> Date: Tue, 2 May 2023 20:13:05 +0000 (GMT) List-Id: https://gcc.gnu.org/g:9eed31b91ce73a9499297bf8ef2c2b7ce4c8d79b commit r11-10693-g9eed31b91ce73a9499297bf8ef2c2b7ce4c8d79b Author: Jakub Jelinek Date: Wed Dec 21 09:05:27 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.c (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/pt.c | 5 +++ libgomp/testsuite/libgomp.c++/pr108180.C | 55 ++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 02a74bb3f49..27b5bd1d090 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -18548,6 +18548,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/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 (); +}