public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] c++: Fix crash in gimplifier with paren init of aggregates [PR94155]
@ 2020-03-30 20:28 Marek Polacek
  2020-04-03 19:01 ` Jason Merrill
  0 siblings, 1 reply; 8+ messages in thread
From: Marek Polacek @ 2020-03-30 20:28 UTC (permalink / raw)
  To: GCC Patches, Jason Merrill

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.  So
fill in the indexes manually, here we have an array, and we can simply
assign indexes starting from 0.

Bootstrapped/regtested on x86_64-linux, ok for trunk?

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

	* g++.dg/cpp2a/paren-init22.C: New test.
---
 gcc/cp/decl.c                             |  6 ++++++
 gcc/testsuite/g++.dg/cpp2a/paren-init22.C | 15 +++++++++++++++
 2 files changed, 21 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/cpp2a/paren-init22.C

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 69a238997b4..80dd2d8b931 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -6754,6 +6754,12 @@ check_initializer (tree decl, tree init, int flags, vec<tree, va_gc> **cleanups)
 	      init = build_constructor_from_list (init_list_type_node, init);
 	      CONSTRUCTOR_IS_DIRECT_INIT (init) = true;
 	      CONSTRUCTOR_IS_PAREN_INIT (init) = true;
+	      /* The gimplifier expects that the front end fills in all of the
+		 indices.  Normally, reshape_init_array fills these in, but we
+		 don't call reshape_init because that does nothing when it gets
+		 CONSTRUCTOR_IS_PAREN_INIT.  */
+	      for (unsigned int i = 0; i < CONSTRUCTOR_NELTS (init); i++)
+		CONSTRUCTOR_ELT (init, i)->index = size_int (i);
 	    }
 	}
       else if (TREE_CODE (init) == TREE_LIST
diff --git a/gcc/testsuite/g++.dg/cpp2a/paren-init22.C b/gcc/testsuite/g++.dg/cpp2a/paren-init22.C
new file mode 100644
index 00000000000..1b2959e7731
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/paren-init22.C
@@ -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}});
+}

base-commit: 48e331d63827a0500670d685c0fe7d609e0a807a
-- 
Marek Polacek • Red Hat, Inc. • 300 A St, Boston, MA


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

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

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-30 20:28 [PATCH] c++: Fix crash in gimplifier with paren init of aggregates [PR94155] Marek Polacek
2020-04-03 19:01 ` Jason Merrill
2020-04-04  1:08   ` [PATCH v2] " Marek Polacek
2020-04-04  2:39     ` Jason Merrill
2020-04-04 17:56       ` Marek Polacek
2020-04-06 14:47         ` Jason Merrill
2020-04-06 15:57           ` [PATCH v3] " Marek Polacek
2020-04-06 16:35             ` Jason Merrill

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