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] Fix PR c/14069


Hi!

We shouldn't be passing incorrect trees down to middle-end after issuing
diagnostics.
Bootstrapped/regtested on x86_64-redhat-linux and i386-redhat-linux, ok
for trunk/3.4/3.3?

2004-03-22  Jakub Jelinek  <jakub@redhat.com>

	PR c/14069
	* c-decl.c (finish_struct): Change type of incorrect flexible array
	field into error_mark_node.

	* gcc.dg/20040322-1.c: New test.

--- gcc/c-decl.c.jj	2004-03-16 16:24:41.000000000 +0100
+++ gcc/c-decl.c	2004-03-22 10:30:45.659169289 +0100
@@ -5008,11 +5008,20 @@ finish_struct (tree t, tree fieldlist, t
 	  && TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (x))) == NULL_TREE)
 	{
 	  if (TREE_CODE (t) == UNION_TYPE)
-	    error ("%Jflexible array member in union", x);
+	    {
+	      error ("%Jflexible array member in union", x);
+	      TREE_TYPE (x) = error_mark_node;
+	    }
 	  else if (TREE_CHAIN (x) != NULL_TREE)
-	    error ("%Jflexible array member not at end of struct", x);
+	    {
+	      error ("%Jflexible array member not at end of struct", x);
+	      TREE_TYPE (x) = error_mark_node;
+	    }
 	  else if (! saw_named_field)
-	    error ("%Jflexible array member in otherwise empty struct", x);
+	    {
+	      error ("%Jflexible array member in otherwise empty struct", x);
+	      TREE_TYPE (x) = error_mark_node;
+	    }
 	}
 
       if (pedantic && TREE_CODE (t) == RECORD_TYPE
--- gcc/testsuite/gcc.dg/20040322-1.c.jj	2004-01-21 17:12:41.000000000 +0100
+++ gcc/testsuite/gcc.dg/20040322-1.c	2004-03-22 11:38:23.858823993 +0100
@@ -0,0 +1,4 @@
+/* PR c/14069 */
+/* { dg-do compile } */
+struct S { int a; char b[]; char *c; }; /* { dg-error "error" "flexible array member not" } */
+struct S s = { .b = "foo", .c = .b }; /* { dg-error "error" "parse error before" } */

	Jakub


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