This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Don't ICE if COMPOUND_LITERAL_EXPR's DECL_INITIAL isn't CONSTRUCTOR (PR c/54363)


Hi!

On this testcase, we ICE in optimize_compound_literals_in_ctor
because init isn't CONSTRUCTOR, but the recursive call relies on it
being a CONSTRUCTOR.

Either we can add that check as the patch does, making the optimization
tiny bit more robust (the rest of the gimplifier handles non-CONSTRUCTOR
DECL_INITIAL of COMPOUND_LITERAL_EXPR just fine), or the C FE would need to
be somehow fixed to always emit a CONSTRUCTOR.

Joseph, what do you prefer here?

Bootstrapped/regtested on x86_64-linux and i686-linux.

2012-08-24  Jakub Jelinek  <jakub@redhat.com>

	PR c/54363
	* gimplify.c (optimize_compound_literals_in_ctor): Only recurse
	if init is a CONSTRUCTOR.

	* gcc.dg/pr54363.c: New test.

--- gcc/gimplify.c.jj	2012-08-15 10:55:33.000000000 +0200
+++ gcc/gimplify.c	2012-08-24 11:01:55.253815273 +0200
@@ -3857,7 +3857,8 @@ optimize_compound_literals_in_ctor (tree
 
 	  if (!TREE_ADDRESSABLE (value)
 	      && !TREE_ADDRESSABLE (decl)
-	      && init)
+	      && init
+	      && TREE_CODE (init) == CONSTRUCTOR)
 	    newval = optimize_compound_literals_in_ctor (init);
 	}
       if (newval == value)
--- gcc/testsuite/gcc.dg/pr54363.c.jj	2012-08-24 11:34:49.857494287 +0200
+++ gcc/testsuite/gcc.dg/pr54363.c	2012-08-24 11:36:20.943061045 +0200
@@ -0,0 +1,12 @@
+/* PR c/54363 */
+/* { dg-do compile } */
+/* { dg-options "-std=gnu99" } */
+
+struct S { char **a; };
+
+void
+test (void)
+{
+  struct S b = { .a = (char **) { "a", "b" } }; /* { dg-warning "(initialization|excess elements)" } */
+  struct S c = { .a = (char *[]) { "a", "b" } };
+}

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]