public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/110382] New: [13/14 Regression] internal compiler error: in verify_ctor_sanity
@ 2023-06-23 22:21 mpolacek at gcc dot gnu.org
  2023-06-23 22:21 ` [Bug c++/110382] " mpolacek at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-06-23 22:21 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 110382
           Summary: [13/14 Regression] internal compiler error: in
                    verify_ctor_sanity
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mpolacek at gcc dot gnu.org
  Target Milestone: ---

using value_type = double;
struct FOO {
  value_type a = 0;
};
constexpr value_type sum_8_foos(FOO *foos) {
  value_type sum = 0;
  for (int i = 0;; ++i) {
    auto foo = foos[0];
    sum += foo.a;
  }
}
constexpr value_type test_1() {
  FOO foos[1];
  return sum_8_foos(foos);
}
int main() { return test_1(); }

$ ./cc1plus -quiet bz.C 
bz.C: In function ‘int main()’:
bz.C:16:27:   in ‘constexpr’ expansion of ‘test_1()’
bz.C:14:20:   in ‘constexpr’ expansion of ‘sum_8_foos(((FOO*)(& foos)))’
bz.C:16:27: internal compiler error: in verify_ctor_sanity, at
cp/constexpr.cc:5001
   16 | int main() { return test_1(); }
      |                     ~~~~~~^~
0xd9dfa1 verify_ctor_sanity
        /home/mpolacek/src/gcc/gcc/cp/constexpr.cc:5001
0xd9e1a6 cxx_eval_bare_aggregate
        /home/mpolacek/src/gcc/gcc/cp/constexpr.cc:5029
0xda8eaa cxx_eval_constant_expression
        /home/mpolacek/src/gcc/gcc/cp/constexpr.cc:7606
0xd9b18b cxx_eval_array_reference
        /home/mpolacek/src/gcc/gcc/cp/constexpr.cc:4297
0xda8aff cxx_eval_constant_expression
        /home/mpolacek/src/gcc/gcc/cp/constexpr.cc:7531
0xda0db8 cxx_eval_indirect_ref
        /home/mpolacek/src/gcc/gcc/cp/constexpr.cc:5674
0xda8503 cxx_eval_constant_expression
        /home/mpolacek/src/gcc/gcc/cp/constexpr.cc:7373
0xda7807 cxx_eval_constant_expression
        /home/mpolacek/src/gcc/gcc/cp/constexpr.cc:7173
0xda51da cxx_eval_statement_list
        /home/mpolacek/src/gcc/gcc/cp/constexpr.cc:6567
0xdaa61e cxx_eval_constant_expression
        /home/mpolacek/src/gcc/gcc/cp/constexpr.cc:7843
0xdaa697 cxx_eval_constant_expression
        /home/mpolacek/src/gcc/gcc/cp/constexpr.cc:7847
0xda574d cxx_eval_loop_expr
        /home/mpolacek/src/gcc/gcc/cp/constexpr.cc:6640
0xdaaa43 cxx_eval_constant_expression
        /home/mpolacek/src/gcc/gcc/cp/constexpr.cc:7926
0xda51da cxx_eval_statement_list
        /home/mpolacek/src/gcc/gcc/cp/constexpr.cc:6567
0xdaa61e cxx_eval_constant_expression
        /home/mpolacek/src/gcc/gcc/cp/constexpr.cc:7843
0xdaa697 cxx_eval_constant_expression
        /home/mpolacek/src/gcc/gcc/cp/constexpr.cc:7847
0xda51da cxx_eval_statement_list
        /home/mpolacek/src/gcc/gcc/cp/constexpr.cc:6567
0xdaa61e cxx_eval_constant_expression
        /home/mpolacek/src/gcc/gcc/cp/constexpr.cc:7843
0xdaa697 cxx_eval_constant_expression
        /home/mpolacek/src/gcc/gcc/cp/constexpr.cc:7847
0xd96576 cxx_eval_call_expression
        /home/mpolacek/src/gcc/gcc/cp/constexpr.cc:3102

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

* [Bug c++/110382] [13/14 Regression] internal compiler error: in verify_ctor_sanity
  2023-06-23 22:21 [Bug c++/110382] New: [13/14 Regression] internal compiler error: in verify_ctor_sanity mpolacek at gcc dot gnu.org
@ 2023-06-23 22:21 ` mpolacek at gcc dot gnu.org
  2023-07-21 17:31 ` mpolacek at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-06-23 22:21 UTC (permalink / raw)
  To: gcc-bugs

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |mpolacek at gcc dot gnu.org
           Priority|P3                          |P2
           Keywords|                            |ice-on-valid-code
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2023-06-23
     Ever confirmed|0                           |1
   Target Milestone|---                         |13.2

--- Comment #1 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Started with r13-5693, so mine.

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

* [Bug c++/110382] [13/14 Regression] internal compiler error: in verify_ctor_sanity
  2023-06-23 22:21 [Bug c++/110382] New: [13/14 Regression] internal compiler error: in verify_ctor_sanity mpolacek at gcc dot gnu.org
  2023-06-23 22:21 ` [Bug c++/110382] " mpolacek at gcc dot gnu.org
@ 2023-07-21 17:31 ` mpolacek at gcc dot gnu.org
  2023-07-21 18:29 ` mpolacek at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-07-21 17:31 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Cleaned-up test:

struct S {
  double a = 0;
};

constexpr double
g ()
{
  S arr[1];
  S s = arr[0];
  return s.a;
}

int main() { return  g (); }

Note that changing
double a = 0;
to
double a = 0.;
gets rid of the ICE!

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

* [Bug c++/110382] [13/14 Regression] internal compiler error: in verify_ctor_sanity
  2023-06-23 22:21 [Bug c++/110382] New: [13/14 Regression] internal compiler error: in verify_ctor_sanity mpolacek at gcc dot gnu.org
  2023-06-23 22:21 ` [Bug c++/110382] " mpolacek at gcc dot gnu.org
  2023-07-21 17:31 ` mpolacek at gcc dot gnu.org
@ 2023-07-21 18:29 ` mpolacek at gcc dot gnu.org
  2023-07-25 18:06 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-07-21 18:29 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
(In reply to Marek Polacek from comment #2)
> Note that changing
> double a = 0;
> to
> double a = 0.;
> gets rid of the ICE!

...because the latter means the {} is reduced_constant_expression_p and
TREE_CONSTANT, so we never call cxx_eval_bare_aggregate.

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

* [Bug c++/110382] [13/14 Regression] internal compiler error: in verify_ctor_sanity
  2023-06-23 22:21 [Bug c++/110382] New: [13/14 Regression] internal compiler error: in verify_ctor_sanity mpolacek at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2023-07-21 18:29 ` mpolacek at gcc dot gnu.org
@ 2023-07-25 18:06 ` cvs-commit at gcc dot gnu.org
  2023-07-25 18:07 ` [Bug c++/110382] [13 " mpolacek at gcc dot gnu.org
  2023-07-27  9:27 ` rguenth at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-07-25 18:06 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:

https://gcc.gnu.org/g:6e424febfbcb27c21a7fe3a137e614765f9cf9d2

commit r14-2762-g6e424febfbcb27c21a7fe3a137e614765f9cf9d2
Author: Marek Polacek <polacek@redhat.com>
Date:   Fri Jul 21 17:48:37 2023 -0400

    c++: fix ICE with constexpr ARRAY_REF [PR110382]

    This code in cxx_eval_array_reference has been hard to get right.
    In r12-2304 I added some code; in r13-5693 I removed some of it.

    Here the problematic line is "S s = arr[0];" which causes a crash
    on the assert in verify_ctor_sanity:

      gcc_assert (!ctx->object || !DECL_P (ctx->object)
                  || ctx->global->get_value (ctx->object) == ctx->ctor);

    ctx->object is the VAR_DECL 's', which is correct here.  The second
    line points to the problem: we replaced ctx->ctor in
    cxx_eval_array_reference:

      new_ctx.ctor = build_constructor (elem_type, NULL); // #1

    which I think we shouldn't have; the CONSTRUCTOR we created in
    cxx_eval_constant_expression/DECL_EXPR

      new_ctx.ctor = build_constructor (TREE_TYPE (r), NULL);

    had the right type.

    We still need #1 though.  E.g., in constexpr-96241.C, we never
    set ctx.ctor/object before calling cxx_eval_array_reference, so
    we have to build a CONSTRUCTOR there.  And in constexpr-101371-2.C
    we have a ctx.ctor, but it has the wrong type, so we need a new one.

    We can fix the problem by always clearing the object, and, as an
    optimization, only create/free a new ctor when actually needed.

            PR c++/110382

    gcc/cp/ChangeLog:

            * constexpr.cc (cxx_eval_array_reference): Create a new constructor
            only when we don't already have a matching one.  Clear the object
            when the type is non-scalar.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp1y/constexpr-110382.C: New test.

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

* [Bug c++/110382] [13 Regression] internal compiler error: in verify_ctor_sanity
  2023-06-23 22:21 [Bug c++/110382] New: [13/14 Regression] internal compiler error: in verify_ctor_sanity mpolacek at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2023-07-25 18:06 ` cvs-commit at gcc dot gnu.org
@ 2023-07-25 18:07 ` mpolacek at gcc dot gnu.org
  2023-07-27  9:27 ` rguenth at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-07-25 18:07 UTC (permalink / raw)
  To: gcc-bugs

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[13/14 Regression] internal |[13 Regression] internal
                   |compiler error: in          |compiler error: in
                   |verify_ctor_sanity          |verify_ctor_sanity

--- Comment #5 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed on trunk so far.

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

* [Bug c++/110382] [13 Regression] internal compiler error: in verify_ctor_sanity
  2023-06-23 22:21 [Bug c++/110382] New: [13/14 Regression] internal compiler error: in verify_ctor_sanity mpolacek at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2023-07-25 18:07 ` [Bug c++/110382] [13 " mpolacek at gcc dot gnu.org
@ 2023-07-27  9:27 ` rguenth at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-07-27  9:27 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|13.2                        |13.3

--- Comment #6 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 13.2 is being released, retargeting bugs to GCC 13.3.

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

end of thread, other threads:[~2023-07-27  9:27 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-23 22:21 [Bug c++/110382] New: [13/14 Regression] internal compiler error: in verify_ctor_sanity mpolacek at gcc dot gnu.org
2023-06-23 22:21 ` [Bug c++/110382] " mpolacek at gcc dot gnu.org
2023-07-21 17:31 ` mpolacek at gcc dot gnu.org
2023-07-21 18:29 ` mpolacek at gcc dot gnu.org
2023-07-25 18:06 ` cvs-commit at gcc dot gnu.org
2023-07-25 18:07 ` [Bug c++/110382] [13 " mpolacek at gcc dot gnu.org
2023-07-27  9:27 ` 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).