public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/108180] New: [OpenMP] Passing a class member variable to firstprivate() erroneously calls its dtor
@ 2022-12-19 17:41 info@ebner-markus.de
  2022-12-20 11:56 ` [Bug c++/108180] " jakub at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: info@ebner-markus.de @ 2022-12-19 17:41 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108180

            Bug ID: 108180
           Summary: [OpenMP] Passing a class member variable to
                    firstprivate() erroneously calls its dtor
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: info@ebner-markus.de
  Target Milestone: ---

Created attachment 54128
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54128&action=edit
Minimal example cpp

Following situation:
I have a class. This class has a member variable (itself of a complex type).
The class also has a member function in which an OpenMP loop (#pragma omp
parallel for) is used. This loop accesses the mentioned class member variable
through the firstprivate() flag.
As far as I understood, this should copy the variable into every worker thread
by calling the copy constructor.
However, now upon leaving the class's member function, the dtor of the class
member variable is called.

Here is a code example: https://godbolt.org/z/oxb3Pq9he
The log shows, that the dtor of the mentioned class member variable is
erroneously called twice.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c++/108180] [OpenMP] Passing a class member variable to firstprivate() erroneously calls its dtor
  2022-12-19 17:41 [Bug c++/108180] New: [OpenMP] Passing a class member variable to firstprivate() erroneously calls its dtor info@ebner-markus.de
@ 2022-12-20 11:56 ` jakub at gcc dot gnu.org
  2022-12-21  8:10 ` cvs-commit at gcc dot gnu.org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-12-20 11:56 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108180

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |jakub at gcc dot gnu.org
   Last reconfirmed|                            |2022-12-20
     Ever confirmed|0                           |1

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Created attachment 54130
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54130&action=edit
gcc13-pr108180.patch

Untested fix.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c++/108180] [OpenMP] Passing a class member variable to firstprivate() erroneously calls its dtor
  2022-12-19 17:41 [Bug c++/108180] New: [OpenMP] Passing a class member variable to firstprivate() erroneously calls its dtor info@ebner-markus.de
  2022-12-20 11:56 ` [Bug c++/108180] " jakub at gcc dot gnu.org
@ 2022-12-21  8:10 ` cvs-commit at gcc dot gnu.org
  2022-12-21  8:27 ` jakub at gcc dot gnu.org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-12-21  8:10 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108180

--- Comment #2 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:1119902b6c7c1c50123ed85ec1def8be4772d68c

commit r13-4822-g1119902b6c7c1c50123ed85ec1def8be4772d68c
Author: Jakub Jelinek <jakub@redhat.com>
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  <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.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c++/108180] [OpenMP] Passing a class member variable to firstprivate() erroneously calls its dtor
  2022-12-19 17:41 [Bug c++/108180] New: [OpenMP] Passing a class member variable to firstprivate() erroneously calls its dtor info@ebner-markus.de
  2022-12-20 11:56 ` [Bug c++/108180] " jakub at gcc dot gnu.org
  2022-12-21  8:10 ` cvs-commit at gcc dot gnu.org
@ 2022-12-21  8:27 ` jakub at gcc dot gnu.org
  2023-02-10 17:44 ` cvs-commit at gcc dot gnu.org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-12-21  8:27 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108180

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Fixed on the trunk so far.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c++/108180] [OpenMP] Passing a class member variable to firstprivate() erroneously calls its dtor
  2022-12-19 17:41 [Bug c++/108180] New: [OpenMP] Passing a class member variable to firstprivate() erroneously calls its dtor info@ebner-markus.de
                   ` (2 preceding siblings ...)
  2022-12-21  8:27 ` jakub at gcc dot gnu.org
@ 2023-02-10 17:44 ` cvs-commit at gcc dot gnu.org
  2023-05-02 20:13 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-02-10 17:44 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108180

--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-12 branch has been updated by Jakub Jelinek
<jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:c4b8949a3ad0a2259388841f3c833876a19bd2a2

commit r12-9131-gc4b8949a3ad0a2259388841f3c833876a19bd2a2
Author: Jakub Jelinek <jakub@redhat.com>
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  <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.

    (cherry picked from commit 1119902b6c7c1c50123ed85ec1def8be4772d68c)

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c++/108180] [OpenMP] Passing a class member variable to firstprivate() erroneously calls its dtor
  2022-12-19 17:41 [Bug c++/108180] New: [OpenMP] Passing a class member variable to firstprivate() erroneously calls its dtor info@ebner-markus.de
                   ` (3 preceding siblings ...)
  2023-02-10 17:44 ` cvs-commit at gcc dot gnu.org
@ 2023-05-02 20:13 ` cvs-commit at gcc dot gnu.org
  2023-05-03  9:34 ` jakub at gcc dot gnu.org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-05-02 20:13 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108180

--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-11 branch has been updated by Jakub Jelinek
<jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:9eed31b91ce73a9499297bf8ef2c2b7ce4c8d79b

commit r11-10693-g9eed31b91ce73a9499297bf8ef2c2b7ce4c8d79b
Author: Jakub Jelinek <jakub@redhat.com>
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  <jakub@redhat.com>

            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)

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c++/108180] [OpenMP] Passing a class member variable to firstprivate() erroneously calls its dtor
  2022-12-19 17:41 [Bug c++/108180] New: [OpenMP] Passing a class member variable to firstprivate() erroneously calls its dtor info@ebner-markus.de
                   ` (4 preceding siblings ...)
  2023-05-02 20:13 ` cvs-commit at gcc dot gnu.org
@ 2023-05-03  9:34 ` jakub at gcc dot gnu.org
  2023-05-03 15:20 ` cvs-commit at gcc dot gnu.org
  2023-05-04  7:22 ` jakub at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-05-03  9:34 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108180

--- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Fixed for 11.4 as well.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c++/108180] [OpenMP] Passing a class member variable to firstprivate() erroneously calls its dtor
  2022-12-19 17:41 [Bug c++/108180] New: [OpenMP] Passing a class member variable to firstprivate() erroneously calls its dtor info@ebner-markus.de
                   ` (5 preceding siblings ...)
  2023-05-03  9:34 ` jakub at gcc dot gnu.org
@ 2023-05-03 15:20 ` cvs-commit at gcc dot gnu.org
  2023-05-04  7:22 ` jakub at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-05-03 15:20 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108180

--- Comment #7 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-10 branch has been updated by Jakub Jelinek
<jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:2a8357535300e9d4d6126d7b3ce4cd951f0eb6aa

commit r10-11351-g2a8357535300e9d4d6126d7b3ce4cd951f0eb6aa
Author: Jakub Jelinek <jakub@redhat.com>
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  <jakub@redhat.com>

            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)

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c++/108180] [OpenMP] Passing a class member variable to firstprivate() erroneously calls its dtor
  2022-12-19 17:41 [Bug c++/108180] New: [OpenMP] Passing a class member variable to firstprivate() erroneously calls its dtor info@ebner-markus.de
                   ` (6 preceding siblings ...)
  2023-05-03 15:20 ` cvs-commit at gcc dot gnu.org
@ 2023-05-04  7:22 ` jakub at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-05-04  7:22 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108180

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|ASSIGNED                    |RESOLVED

--- Comment #8 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Fixed for 10.5 too.

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2023-05-04  7:22 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-19 17:41 [Bug c++/108180] New: [OpenMP] Passing a class member variable to firstprivate() erroneously calls its dtor info@ebner-markus.de
2022-12-20 11:56 ` [Bug c++/108180] " jakub at gcc dot gnu.org
2022-12-21  8:10 ` cvs-commit at gcc dot gnu.org
2022-12-21  8:27 ` jakub at gcc dot gnu.org
2023-02-10 17:44 ` cvs-commit at gcc dot gnu.org
2023-05-02 20:13 ` cvs-commit at gcc dot gnu.org
2023-05-03  9:34 ` jakub at gcc dot gnu.org
2023-05-03 15:20 ` cvs-commit at gcc dot gnu.org
2023-05-04  7:22 ` jakub at gcc dot gnu.org

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).