public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [C PATCH] Fix ICE-on-invalid with enum forward declaration (PR c/70851)
@ 2016-05-02 10:27 Marek Polacek
  2016-05-02 10:42 ` Bernd Schmidt
  0 siblings, 1 reply; 2+ messages in thread
From: Marek Polacek @ 2016-05-02 10:27 UTC (permalink / raw)
  To: GCC Patches, Joseph Myers

Here, the problem was that we weren't diagnosing invalid code when an array
dimension was of incomplete enum type.  That led to an ICE in gimplifier.

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

2016-05-02  Marek Polacek  <polacek@redhat.com>

	PR c/70851
	* c-decl.c (grokdeclarator): Diagnose when array's size has an
	incomplete type.

	* gcc.dg/enum-incomplete-3.c: New test.

diff --git gcc/c/c-decl.c gcc/c/c-decl.c
index 16e4250..7094efc 100644
--- gcc/c/c-decl.c
+++ gcc/c/c-decl.c
@@ -5799,10 +5799,21 @@ grokdeclarator (const struct c_declarator *declarator,
 		  {
 		    if (name)
 		      error_at (loc, "size of array %qE has non-integer type",
-			  	name);
+				name);
 		    else
 		      error_at (loc,
-			  	"size of unnamed array has non-integer type");
+				"size of unnamed array has non-integer type");
+		    size = integer_one_node;
+		  }
+		/* This can happen with enum forward declaration.  */
+		else if (!COMPLETE_TYPE_P (TREE_TYPE (size)))
+		  {
+		    if (name)
+		      error_at (loc, "size of array %qE has incomplete type",
+				name);
+		    else
+		      error_at (loc, "size of unnamed array has incomplete "
+				"type");
 		    size = integer_one_node;
 		  }
 
diff --git gcc/testsuite/gcc.dg/enum-incomplete-3.c gcc/testsuite/gcc.dg/enum-incomplete-3.c
index e69de29..db1138b 100644
--- gcc/testsuite/gcc.dg/enum-incomplete-3.c
+++ gcc/testsuite/gcc.dg/enum-incomplete-3.c
@@ -0,0 +1,20 @@
+/* PR c/70851 */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+enum E e; /* { dg-error "storage size" } */
+
+void bar (int [e]); /* { dg-error "size of unnamed array has incomplete type" } */
+void bar2 (int [][e]); /* { dg-error "size of unnamed array has incomplete type" } */
+
+void
+foo (void)
+{
+  int a1[e]; /* { dg-error "size of array .a1. has incomplete type" } */
+  int a2[e][3]; /* { dg-error "size of array .a2. has incomplete type" } */
+
+  struct S
+  {
+    int a3[e]; /* { dg-error "size of array .a3. has incomplete type" } */
+  };
+}

	Marek

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

* Re: [C PATCH] Fix ICE-on-invalid with enum forward declaration (PR c/70851)
  2016-05-02 10:27 [C PATCH] Fix ICE-on-invalid with enum forward declaration (PR c/70851) Marek Polacek
@ 2016-05-02 10:42 ` Bernd Schmidt
  0 siblings, 0 replies; 2+ messages in thread
From: Bernd Schmidt @ 2016-05-02 10:42 UTC (permalink / raw)
  To: Marek Polacek, GCC Patches, Joseph Myers



On 05/02/2016 12:27 PM, Marek Polacek wrote:
> Here, the problem was that we weren't diagnosing invalid code when an array
> dimension was of incomplete enum type.  That led to an ICE in gimplifier.
>
> Bootstrapped/regtested on x86_64-linux, ok for trunk?
>
> 2016-05-02  Marek Polacek  <polacek@redhat.com>
>
> 	PR c/70851
> 	* c-decl.c (grokdeclarator): Diagnose when array's size has an
> 	incomplete type.
>
> 	* gcc.dg/enum-incomplete-3.c: New test.

Ok.


Bernd

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

end of thread, other threads:[~2016-05-02 10:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-02 10:27 [C PATCH] Fix ICE-on-invalid with enum forward declaration (PR c/70851) Marek Polacek
2016-05-02 10:42 ` Bernd Schmidt

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