public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/94219] New: ICE in cxx_eval_bare_aggregate, at cp/constexpr.c:3790
@ 2020-03-18 22:24 ppalka at gcc dot gnu.org
  2020-03-19  8:17 ` [Bug c++/94219] " marxin at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: ppalka at gcc dot gnu.org @ 2020-03-18 22:24 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 94219
           Summary: ICE in cxx_eval_bare_aggregate, at cp/constexpr.c:3790
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ppalka at gcc dot gnu.org
  Target Milestone: ---

$ cat 94066-struct.C
struct A { long x; };

struct U;
constexpr A foo(U *up);

struct U {       // struct instead of union
  A a = foo(this); int y;
};

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

extern constexpr U u = {};

static_assert(u.y == 11, "");
static_assert(u.a.x == 42, "");
$ g++ -std=c++14 94066-struct.C
94066-modified.C:15:25: internal compiler error: in cxx_eval_bare_aggregate, at
cp/constexpr.c:3790
   18 | extern constexpr U u = {};
      |                         ^
0x602956 cxx_eval_bare_aggregate
        /home/patrick/code/gcc-master/gcc/cp/constexpr.c:3790
0x941caf cxx_eval_constant_expression
        /home/patrick/code/gcc-master/gcc/cp/constexpr.c:5895
0x944914 cxx_eval_outermost_constant_expr
        /home/patrick/code/gcc-master/gcc/cp/constexpr.c:6451
0x9498c4 maybe_constant_init_1
        /home/patrick/code/gcc-master/gcc/cp/constexpr.c:6908
0xb1919c store_init_value(tree_node*, tree_node*, vec<tree_node*, va_gc,
vl_embed>**, int)
        /home/patrick/code/gcc-master/gcc/cp/typeck2.c:889
0x9acc22 check_initializer
        /home/patrick/code/gcc-master/gcc/cp/decl.c:6838
0x9ae917 cp_finish_decl(tree_node*, tree_node*, bool, tree_node*, int)
        /home/patrick/code/gcc-master/gcc/cp/decl.c:7764
0xa57a9d cp_parser_init_declarator
        /home/patrick/code/gcc-master/gcc/cp/parser.c:20837
0xa378f3 cp_parser_simple_declaration
        /home/patrick/code/gcc-master/gcc/cp/parser.c:13689
0xa5fd97 cp_parser_declaration
        /home/patrick/code/gcc-master/gcc/cp/parser.c:13388
0xa60517 cp_parser_translation_unit
        /home/patrick/code/gcc-master/gcc/cp/parser.c:4731
0xa60517 c_parse_file()
        /home/patrick/code/gcc-master/gcc/cp/parser.c:43758
0xb70dcb c_common_parse_file()
        /home/patrick/code/gcc-master/gcc/c-family/c-opts.c:1186



This is closely related to PR c++/94066, but unlike that PR, this one is not a
regression AFAICT.

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

* [Bug c++/94219] ICE in cxx_eval_bare_aggregate, at cp/constexpr.c:3790
  2020-03-18 22:24 [Bug c++/94219] New: ICE in cxx_eval_bare_aggregate, at cp/constexpr.c:3790 ppalka at gcc dot gnu.org
@ 2020-03-19  8:17 ` marxin at gcc dot gnu.org
  2020-04-01 21:41 ` ppalka at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: marxin at gcc dot gnu.org @ 2020-03-19  8:17 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Liška <marxin at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jason at gcc dot gnu.org,
                   |                            |marxin at gcc dot gnu.org

--- Comment #1 from Martin Liška <marxin at gcc dot gnu.org> ---
With -std=c++14 it started with r5-5013-g60813a463b1e1398, it was rejected
before the revision:

pr94219.cc: In function ‘constexpr A foo(U*)’:
pr94219.cc:13:1: error: body of constexpr function ‘constexpr A foo(U*)’ not a
return-statement
 }
 ^
pr94219.cc: At global scope:
pr94219.cc:7:17: error: ‘constexpr A foo(U*)’ called in a constant expression
   A a = foo(this); int y;
                 ^
pr94219.cc:17:1: error: non-constant condition for static assertion
 static_assert(u.y == 11, "");
 ^
pr94219.cc:18:1: error: non-constant condition for static assertion
 static_assert(u.a.x == 42, "");
 ^

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

* [Bug c++/94219] ICE in cxx_eval_bare_aggregate, at cp/constexpr.c:3790
  2020-03-18 22:24 [Bug c++/94219] New: ICE in cxx_eval_bare_aggregate, at cp/constexpr.c:3790 ppalka at gcc dot gnu.org
  2020-03-19  8:17 ` [Bug c++/94219] " marxin at gcc dot gnu.org
@ 2020-04-01 21:41 ` ppalka at gcc dot gnu.org
  2020-04-04 16:18 ` cvs-commit at gcc dot gnu.org
  2020-04-04 16:21 ` ppalka at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: ppalka at gcc dot gnu.org @ 2020-04-01 21:41 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2020-04-01
             Status|UNCONFIRMED                 |ASSIGNED
     Ever confirmed|0                           |1
           Assignee|unassigned at gcc dot gnu.org      |ppalka at gcc dot gnu.org

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

* [Bug c++/94219] ICE in cxx_eval_bare_aggregate, at cp/constexpr.c:3790
  2020-03-18 22:24 [Bug c++/94219] New: ICE in cxx_eval_bare_aggregate, at cp/constexpr.c:3790 ppalka at gcc dot gnu.org
  2020-03-19  8:17 ` [Bug c++/94219] " marxin at gcc dot gnu.org
  2020-04-01 21:41 ` ppalka at gcc dot gnu.org
@ 2020-04-04 16:18 ` cvs-commit at gcc dot gnu.org
  2020-04-04 16:21 ` ppalka at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-04-04 16:18 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 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:37244b217a7329792f4ec48027f63cf5010b0ea8

commit r10-7556-g37244b217a7329792f4ec48027f63cf5010b0ea8
Author: Patrick Palka <ppalka@redhat.com>
Date:   Thu Apr 2 12:59:34 2020 -0400

    c++: Fix constexpr evaluation of self-modifying CONSTRUCTORs [PR94219]

    This PR reveals that cxx_eval_bare_aggregate and cxx_eval_store_expression
do
    not anticipate that a constructor element's initializer could mutate the
    underlying CONSTRUCTOR.  Evaluation of the initializer could add new
elements to
    the underlying CONSTRUCTOR, thereby potentially invalidating any pointers
to
    or assumptions about the CONSTRUCTOR's elements, and so these routines
should be
    prepared for that.

    To fix this problem, this patch makes cxx_eval_bare_aggregate and
    cxx_eval_store_expression recompute the constructor_elt pointers through
which
    we're assigning, after it evaluates the initializer.  Care is taken to to
not
    slow down the common case where the initializer does not modify the
underlying
    CONSTRUCTOR.

    gcc/cp/ChangeLog:

            PR c++/94219
            PR c++/94205
            * constexpr.c (get_or_insert_ctor_field): Split out (while adding
            support for VECTOR_TYPEs, and optimizations for the common case)
            from ...
            (cxx_eval_store_expression): ... here.  Rename local variable
            'changed_active_union_member_p' to 'activated_union_member_p'. 
Record
            the sequence of indexes into 'indexes' that yields the subobject
we're
            assigning to.  Record the integer offsets of the constructor
indexes
            we're assigning through into 'index_pos_hints'.  After evaluating
the
            initializer of the store expression, recompute 'valp' using
'indexes'
            and using 'index_pos_hints' as hints.
            (cxx_eval_bare_aggregate): Tweak comments.  Use
get_or_insert_ctor_field
            to recompute the constructor_elt pointer we're assigning through
after
            evaluating each initializer.

    gcc/testsuite/ChangeLog:

            PR c++/94219
            PR c++/94205
            * g++.dg/cpp1y/constexpr-nsdmi3.C: New test.
            * g++.dg/cpp1y/constexpr-nsdmi4.C: New test.
            * g++.dg/cpp1y/constexpr-nsdmi5.C: New test.
            * g++.dg/cpp1z/lambda-this5.C: New test.

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

* [Bug c++/94219] ICE in cxx_eval_bare_aggregate, at cp/constexpr.c:3790
  2020-03-18 22:24 [Bug c++/94219] New: ICE in cxx_eval_bare_aggregate, at cp/constexpr.c:3790 ppalka at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2020-04-04 16:18 ` cvs-commit at gcc dot gnu.org
@ 2020-04-04 16:21 ` ppalka at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: ppalka at gcc dot gnu.org @ 2020-04-04 16:21 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED
   Target Milestone|---                         |10.0

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

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

end of thread, other threads:[~2020-04-04 16:21 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-18 22:24 [Bug c++/94219] New: ICE in cxx_eval_bare_aggregate, at cp/constexpr.c:3790 ppalka at gcc dot gnu.org
2020-03-19  8:17 ` [Bug c++/94219] " marxin at gcc dot gnu.org
2020-04-01 21:41 ` ppalka at gcc dot gnu.org
2020-04-04 16:18 ` cvs-commit at gcc dot gnu.org
2020-04-04 16:21 ` ppalka 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).