[PATCH] Avoid segfaulting in {start,finish}_decl

Jakub Jelinek jakub@redhat.com
Fri Oct 20 14:44:00 GMT 2000


Hi!

This patch avoids segfaulting on the enclosed testcase (and gives the same
error messages for it as egcs 1.1.2).
Ok to commit?

2000-10-20  Jakub Jelinek  <jakub@redhat.com>

	* c-decl.c (start_decl): Don't segfault if TREE_TYPE is error_mark.
	(finish_decl): Likewise.

	* gcc.dg/noncompile/init-3.c: New test.

--- gcc/c-decl.c.jj	Thu Oct 19 08:30:49 2000
+++ gcc/c-decl.c	Fri Oct 20 23:21:08 2000
@@ -3506,7 +3506,8 @@ start_decl (declarator, declspecs, initi
       default:
 	/* Don't allow initializations for incomplete types
 	   except for arrays which might be completed by the initialization.  */
-	if (COMPLETE_TYPE_P (TREE_TYPE (decl)))
+	if (TREE_CODE (TREE_TYPE (decl)) != ERROR_MARK
+	    && COMPLETE_TYPE_P (TREE_TYPE (decl)))
 	  {
 	    /* A complete type is ok if size is fixed.  */
 
@@ -3677,7 +3678,8 @@ finish_decl (decl, init, asmspec_tree)
       layout_decl (decl, 0);
     }
 
-  if (TREE_CODE (decl) == VAR_DECL)
+  if (TREE_CODE (decl) == VAR_DECL
+      && TREE_CODE (TREE_TYPE (decl)) != ERROR_MARK)
     {
       if (DECL_SIZE (decl) == 0 && COMPLETE_TYPE_P (TREE_TYPE (decl)))
 	layout_decl (decl, 0);
--- gcc/testsuite/gcc.dg/noncompile/init-3.c.jj	Fri Oct 20 23:38:01 2000
+++ gcc/testsuite/gcc.dg/noncompile/init-3.c	Fri Oct 20 23:37:57 2000
@@ -0,0 +1,4 @@
+void die(void)
+{
+  char foo[BAR] = "1234"; /* { dg-error "undeclared|function|incomplete type" } */
+}

	Jakub


More information about the Gcc-patches mailing list