c++: Fix crash in gimplifier with paren init of aggregates [PR94155]
authorMarek Polacek <polacek@redhat.com>
Mon, 30 Mar 2020 19:49:17 +0000 (15:49 -0400)
committerMarek Polacek <polacek@redhat.com>
Mon, 6 Apr 2020 15:23:56 +0000 (11:23 -0400)
Here we crash in the gimplifier because gimplify_init_ctor_eval doesn't
expect null indexes for a constructor:

      /* ??? Here's to hoping the front end fills in all of the indices,
         so we don't have to figure out what's missing ourselves.  */
      gcc_assert (purpose);

The indexes weren't filled because we never called reshape_init: for
a constructor that represents parenthesized initialization of an
aggregate we don't allow brace elision or designated initializers.

PR c++/94155 - crash in gimplifier with paren init of aggregates.
* init.c (build_vec_init): Fill in indexes.

* g++.dg/cpp2a/paren-init22.C: New test.

gcc/cp/ChangeLog
gcc/cp/init.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp2a/paren-init22.C [new file with mode: 0644]

index a382235..fc75879 100644 (file)
@@ -1,3 +1,9 @@
+2020-04-04  Marek Polacek  <polacek@redhat.com>
+           Jason Merrill  <jason@redhat.com>
+
+       PR c++/94155 - crash in gimplifier with paren init of aggregates.
+       * init.c (build_vec_init): Fill in indexes.
+
 2020-04-04  Jason Merrill  <jason@redhat.com>
 
        PR c++/91377
index 27623cf..ea95a3b 100644 (file)
@@ -4438,6 +4438,8 @@ build_vec_init (tree base, tree maxindex, tree init,
            errors = true;
          if (try_const)
            {
+             if (!field)
+               field = size_int (idx);
              tree e = maybe_constant_init (one_init);
              if (reduced_constant_expression_p (e))
                {
index 88bab5d..2983063 100644 (file)
@@ -1,3 +1,8 @@
+2020-04-04  Marek Polacek  <polacek@redhat.com>
+
+       PR c++/94155 - crash in gimplifier with paren init of aggregates.
+       * g++.dg/cpp2a/paren-init22.C: New test.
+
 2020-04-05  Iain Sandoe  <iain@sandoe.co.uk>
 
        * g++.dg/coroutines/torture/co-await-14-template-traits.C: Rename...
diff --git a/gcc/testsuite/g++.dg/cpp2a/paren-init22.C b/gcc/testsuite/g++.dg/cpp2a/paren-init22.C
new file mode 100644 (file)
index 0000000..1b2959e
--- /dev/null
@@ -0,0 +1,15 @@
+// PR c++/94155 - crash in gimplifier with paren init of aggregates.
+// { dg-do compile { target c++2a } }
+
+struct S { int i, j; };
+
+struct A {
+  S s;
+  constexpr A(S e) : s(e) {}
+};
+
+void
+f()
+{
+  A g[1]({{1, 1}});
+}