From: Jakub Jelinek <jakub@redhat.com>
To: gcc-patches@gcc.gnu.org
Subject: [committed] openmp: Don't try to destruct DECL_OMP_PRIVATIZED_MEMBER vars [PR108180]
Date: Wed, 21 Dec 2022 09:23:19 +0100 [thread overview]
Message-ID: <Y6LCdySCuQk6V90v@tucnak> (raw)
Hi!
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.
Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk
so far.
2022-12-21 Jakub Jelinek <jakub@redhat.com>
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.
--- gcc/cp/pt.cc.jj 2022-12-19 11:09:13.499170642 +0100
+++ gcc/cp/pt.cc 2022-12-20 12:13:59.406097521 +0100
@@ -18895,6 +18895,11 @@ tsubst_expr (tree t, tree args, tsubst_f
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)
ndecl = tsubst_decomp_names (decl, pattern_decl, args,
--- libgomp/testsuite/libgomp.c++/pr108180.C.jj 2022-12-20 12:54:21.077793817 +0100
+++ libgomp/testsuite/libgomp.c++/pr108180.C 2022-12-20 12:53:04.740905961 +0100
@@ -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 N>
+ 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 ();
+}
Jakub
reply other threads:[~2022-12-21 8:23 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=Y6LCdySCuQk6V90v@tucnak \
--to=jakub@redhat.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).