public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/94066] [8/9/10 Regression] ICE (starting/ending union member lifetime) in cxx_eval_bare_aggregate, at cp/constexpr.c:3790 since r6-7592
       [not found] <bug-94066-4@http.gcc.gnu.org/bugzilla/>
@ 2020-03-08 16:41 ` ppalka at gcc dot gnu.org
  2020-03-08 16:54 ` ppalka at gcc dot gnu.org
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 10+ messages in thread
From: ppalka at gcc dot gnu.org @ 2020-03-08 16:41 UTC (permalink / raw)
  To: gcc-bugs

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

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ppalka at gcc dot gnu.org

--- Comment #4 from Patrick Palka <ppalka at gcc dot gnu.org> ---
We also ICE elsewhere with the following modified testcase:

$ cat 94066.C
union U;

constexpr long foo(U *up);

union U {
  long a = foo(this);
  int y;
};

constexpr long foo(U *up) {
  up->y = 11;
  return 42;
}

extern constexpr U u = {};
$ g++ -std=c++17 94066.C
94066.C:15:26: internal compiler error: in output_constructor_regular_field, at
varasm.c:5230
   15 | extern constexpr U u = {};
      |                          ^
0x82f159 output_constructor_regular_field
        /home/patrick/code/gcc/gcc/varasm.c:5230
0x82f159 output_constructor
        /home/patrick/code/gcc/gcc/varasm.c:5536
0x1375894 output_constant
        /home/patrick/code/gcc/gcc/varasm.c:4908
0x1375894 assemble_variable_contents
        /home/patrick/code/gcc/gcc/varasm.c:2148
0x137e152 assemble_variable(tree_node*, int, int, int)
        /home/patrick/code/gcc/gcc/varasm.c:2327
0x1380c79 varpool_node::assemble_decl()
        /home/patrick/code/gcc/gcc/varpool.c:587
0xc209ec output_in_order
        /home/patrick/code/gcc/gcc/cgraphunit.c:2564
0xc209ec symbol_table::compile()
        /home/patrick/code/gcc/gcc/cgraphunit.c:2801
0xc22eec symbol_table::compile()
        /home/patrick/code/gcc/gcc/cgraphunit.c:2717
0xc22eec symbol_table::finalize_compilation_unit()
        /home/patrick/code/gcc/gcc/cgraphunit.c:2984

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

* [Bug c++/94066] [8/9/10 Regression] ICE (starting/ending union member lifetime) in cxx_eval_bare_aggregate, at cp/constexpr.c:3790 since r6-7592
       [not found] <bug-94066-4@http.gcc.gnu.org/bugzilla/>
  2020-03-08 16:41 ` [Bug c++/94066] [8/9/10 Regression] ICE (starting/ending union member lifetime) in cxx_eval_bare_aggregate, at cp/constexpr.c:3790 since r6-7592 ppalka at gcc dot gnu.org
@ 2020-03-08 16:54 ` ppalka at gcc dot gnu.org
  2020-03-09 14:30 ` jakub at gcc dot gnu.org
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 10+ messages in thread
From: ppalka at gcc dot gnu.org @ 2020-03-08 16:54 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Also if we add an explicitly defaulted constructor "U() = default;" to U in the
original test case, then

using GCC 9 /w -std=c++17 we get:
94066.C:16:25:   in ‘constexpr’ expansion of ‘foo((&*this))’
94066.C:12:9: error: change of the active member of a union from ‘U::a’ to
‘U::y’
   12 |   up->y = 11;
      |   ~~~~~~^~~~
94066.C:16: confused by earlier errors, bailing out


using GCC 9 /w -std=c++2a compiles successfully, and we think U::y is the
active member, but static_assert(u.y == 11) fails with "error: ‘(((int)A{42})
== 11)’ is not a constant expression"


using GCC trunk /w -std=c++17 we get an active-member diagnostic as in GCC 9,
and the same ICE as in #c1


using GCC trunk /w -std=c++2a we get same behavior as in GCC 9 /w -std=c++2a

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

* [Bug c++/94066] [8/9/10 Regression] ICE (starting/ending union member lifetime) in cxx_eval_bare_aggregate, at cp/constexpr.c:3790 since r6-7592
       [not found] <bug-94066-4@http.gcc.gnu.org/bugzilla/>
  2020-03-08 16:41 ` [Bug c++/94066] [8/9/10 Regression] ICE (starting/ending union member lifetime) in cxx_eval_bare_aggregate, at cp/constexpr.c:3790 since r6-7592 ppalka at gcc dot gnu.org
  2020-03-08 16:54 ` ppalka at gcc dot gnu.org
@ 2020-03-09 14:30 ` jakub at gcc dot gnu.org
  2020-03-09 15:55 ` hstong at ca dot ibm.com
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 10+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-03-09 14:30 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
The standard seems to say a union member becomes active when the constructor
finishes, not when it starts, so what wording prevents changing the active
member during the construction?

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

* [Bug c++/94066] [8/9/10 Regression] ICE (starting/ending union member lifetime) in cxx_eval_bare_aggregate, at cp/constexpr.c:3790 since r6-7592
       [not found] <bug-94066-4@http.gcc.gnu.org/bugzilla/>
                   ` (2 preceding siblings ...)
  2020-03-09 14:30 ` jakub at gcc dot gnu.org
@ 2020-03-09 15:55 ` hstong at ca dot ibm.com
  2020-03-16 13:13 ` ppalka at gcc dot gnu.org
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 10+ messages in thread
From: hstong at ca dot ibm.com @ 2020-03-09 15:55 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Hubert Tong <hstong at ca dot ibm.com> ---
(In reply to Jakub Jelinek from comment #6)
> The standard seems to say a union member becomes active when the constructor
> finishes, not when it starts, so what wording prevents changing the active
> member during the construction?

I do not believe there is such wording. Especially in the case presented, the
actual construction of the `a` member can be considered to occur while `y` is
the active member. The lack of such wording may well be unintentional.

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

* [Bug c++/94066] [8/9/10 Regression] ICE (starting/ending union member lifetime) in cxx_eval_bare_aggregate, at cp/constexpr.c:3790 since r6-7592
       [not found] <bug-94066-4@http.gcc.gnu.org/bugzilla/>
                   ` (3 preceding siblings ...)
  2020-03-09 15:55 ` hstong at ca dot ibm.com
@ 2020-03-16 13:13 ` ppalka at gcc dot gnu.org
  2020-03-21 13:51 ` cvs-commit at gcc dot gnu.org
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 10+ messages in thread
From: ppalka at gcc dot gnu.org @ 2020-03-16 13:13 UTC (permalink / raw)
  To: gcc-bugs

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

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |ppalka at gcc dot gnu.org
             Status|NEW                         |ASSIGNED

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

* [Bug c++/94066] [8/9/10 Regression] ICE (starting/ending union member lifetime) in cxx_eval_bare_aggregate, at cp/constexpr.c:3790 since r6-7592
       [not found] <bug-94066-4@http.gcc.gnu.org/bugzilla/>
                   ` (4 preceding siblings ...)
  2020-03-16 13:13 ` ppalka at gcc dot gnu.org
@ 2020-03-21 13:51 ` cvs-commit at gcc dot gnu.org
  2020-03-24 15:35 ` [Bug c++/94066] [8/9 " ppalka at gcc dot gnu.org
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-03-21 13:51 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>:

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

commit r10-7313-gb599bf9d6d1e180d350b71e51e08a66a1bb1546a
Author: Patrick Palka <ppalka@redhat.com>
Date:   Thu Mar 19 09:58:28 2020 -0400

    c++: Reject changing active member of union during initialization [PR94066]

    This patch adds a check to detect changing the active union member during
    initialization of another member of the union in cxx_eval_store_expression.
 It
    uses the CONSTRUCTOR_NO_CLEARING flag as a proxy for whether the non-empty
    CONSTRUCTOR of UNION_TYPE we're assigning to is in the process of being
    initialized.

    This patch additionally fixes an issue in reduced_constant_expression_p
where we
    were returning false for an uninitialized union with no active member. 
This
    lets us correctly reject the uninitialized use in the testcase
    testconstexpr-union4.C that we weren't before.

    gcc/cp/ChangeLog:

            PR c++/94066
            * constexpr.c (reduced_constant_expression_p) [CONSTRUCTOR]:
Properly
            handle unions without an initializer.
            (cxx_eval_component_reference): Emit a different diagnostic when
the
            constructor element corresponding to a union member is NULL.
            (cxx_eval_bare_aggregate): When constructing a union, always set
the
            active union member before evaluating the initializer.  Relax
assertion
            that verifies the index of the constructor element we're
initializing
            hasn't been changed.
            (cxx_eval_store_expression): Diagnose changing the active union
member
            while the union is in the process of being initialized.  After
setting
            an active union member, clear CONSTRUCTOR_NO_CLEARING on the
underlying
            CONSTRUCTOR.
            (cxx_eval_constant_expression) [PLACEHOLDER_EXPR]: Don't re-reduce
a
            CONSTRUCTOR returned by lookup_placeholder.

    gcc/testsuite/ChangeLog:

            PR c++/94066
            * g++.dg/cpp1y/constexpr-union2.C: New test.
            * g++.dg/cpp1y/constexpr-union3.C: New test.
            * g++.dg/cpp1y/constexpr-union4.C: New test.
            * g++.dg/cpp1y/constexpr-union5.C: New test.
            * g++.dg/cpp1y/pr94066.C: New test.
            * g++.dg/cpp1y/pr94066-2.C: New test.
            * g++.dg/cpp1y/pr94066-3.C: New test.
            * g++.dg/cpp2a/constexpr-union1.C: New test.

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

* [Bug c++/94066] [8/9 Regression] ICE (starting/ending union member lifetime) in cxx_eval_bare_aggregate, at cp/constexpr.c:3790 since r6-7592
       [not found] <bug-94066-4@http.gcc.gnu.org/bugzilla/>
                   ` (5 preceding siblings ...)
  2020-03-21 13:51 ` cvs-commit at gcc dot gnu.org
@ 2020-03-24 15:35 ` ppalka at gcc dot gnu.org
  2021-05-14  9:53 ` [Bug c++/94066] [9 " jakub at gcc dot gnu.org
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 10+ messages in thread
From: ppalka at gcc dot gnu.org @ 2020-03-24 15:35 UTC (permalink / raw)
  To: gcc-bugs

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

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[8/9/10 Regression] ICE     |[8/9 Regression] ICE
                   |(starting/ending union      |(starting/ending union
                   |member lifetime) in         |member lifetime) in
                   |cxx_eval_bare_aggregate, at |cxx_eval_bare_aggregate, at
                   |cp/constexpr.c:3790 since   |cp/constexpr.c:3790 since
                   |r6-7592                     |r6-7592

--- Comment #9 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Fixed for GCC 10.

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

* [Bug c++/94066] [9 Regression] ICE (starting/ending union member lifetime) in cxx_eval_bare_aggregate, at cp/constexpr.c:3790 since r6-7592
       [not found] <bug-94066-4@http.gcc.gnu.org/bugzilla/>
                   ` (6 preceding siblings ...)
  2020-03-24 15:35 ` [Bug c++/94066] [8/9 " ppalka at gcc dot gnu.org
@ 2021-05-14  9:53 ` jakub at gcc dot gnu.org
  2021-06-01  8:16 ` rguenth at gcc dot gnu.org
  2022-05-27  8:47 ` rguenth at gcc dot gnu.org
  9 siblings, 0 replies; 10+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-05-14  9:53 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|8.5                         |9.4

--- Comment #10 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
GCC 8 branch is being closed.

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

* [Bug c++/94066] [9 Regression] ICE (starting/ending union member lifetime) in cxx_eval_bare_aggregate, at cp/constexpr.c:3790 since r6-7592
       [not found] <bug-94066-4@http.gcc.gnu.org/bugzilla/>
                   ` (7 preceding siblings ...)
  2021-05-14  9:53 ` [Bug c++/94066] [9 " jakub at gcc dot gnu.org
@ 2021-06-01  8:16 ` rguenth at gcc dot gnu.org
  2022-05-27  8:47 ` rguenth at gcc dot gnu.org
  9 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-06-01  8:16 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|9.4                         |9.5

--- Comment #11 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 9.4 is being released, retargeting bugs to GCC 9.5.

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

* [Bug c++/94066] [9 Regression] ICE (starting/ending union member lifetime) in cxx_eval_bare_aggregate, at cp/constexpr.c:3790 since r6-7592
       [not found] <bug-94066-4@http.gcc.gnu.org/bugzilla/>
                   ` (8 preceding siblings ...)
  2021-06-01  8:16 ` rguenth at gcc dot gnu.org
@ 2022-05-27  8:47 ` rguenth at gcc dot gnu.org
  9 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-05-27  8:47 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
      Known to fail|                            |9.5.0
             Status|ASSIGNED                    |RESOLVED
   Target Milestone|9.5                         |10.0

--- Comment #12 from Richard Biener <rguenth at gcc dot gnu.org> ---
Fixed in GCC 10.

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

end of thread, other threads:[~2022-05-27  8:47 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-94066-4@http.gcc.gnu.org/bugzilla/>
2020-03-08 16:41 ` [Bug c++/94066] [8/9/10 Regression] ICE (starting/ending union member lifetime) in cxx_eval_bare_aggregate, at cp/constexpr.c:3790 since r6-7592 ppalka at gcc dot gnu.org
2020-03-08 16:54 ` ppalka at gcc dot gnu.org
2020-03-09 14:30 ` jakub at gcc dot gnu.org
2020-03-09 15:55 ` hstong at ca dot ibm.com
2020-03-16 13:13 ` ppalka at gcc dot gnu.org
2020-03-21 13:51 ` cvs-commit at gcc dot gnu.org
2020-03-24 15:35 ` [Bug c++/94066] [8/9 " ppalka at gcc dot gnu.org
2021-05-14  9:53 ` [Bug c++/94066] [9 " jakub at gcc dot gnu.org
2021-06-01  8:16 ` rguenth at gcc dot gnu.org
2022-05-27  8:47 ` rguenth 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).