c-decl.c patch for tree-checking abort and spurious error message

Jim Wilson wilson@cygnus.com
Thu Oct 19 17:59:00 GMT 2000


The C compiler triggers an abort in the tree-checking code for this testcase.

sub ()
{
  char array[UNDEFINED] = "foobar";
}

The problem is that there are several places that use COMPLETE_TYPE_P
on TREE_TYPE without first checking for an ERROR_MARK type.  After fixing
this, I noticed that we got two error messages for this testcase instead of
one, so I fixed that also.

2000-10-19  Jim Wilson  <wilson@cygnus.com>

	* c-decl.c (start_decl): Check for error_mark_node type before using
	COMPLETE_TYPE_P.
	(finish_decl): Likewise.  Don't give an error if decl type is
	already error_mark_node.

Index: c-decl.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/c-decl.c,v
retrieving revision 1.168
diff -p -r1.168 c-decl.c
*** c-decl.c	2000/10/17 09:34:20	1.168
--- c-decl.c	2000/10/20 00:38:17
*************** start_decl (declarator, declspecs, initi
*** 3515,3521 ****
        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)))
  	  {
  	    /* A complete type is ok if size is fixed.  */
  
--- 3515,3526 ----
        default:
  	/* Don't allow initializations for incomplete types
  	   except for arrays which might be completed by the initialization.  */
! 
! 	/* This can happen if the array size is an undefined macro.  We already
! 	   gave a warning, so we don't need another one.  */
! 	if (TREE_TYPE (decl) == error_mark_node)
! 	  initialized = 0;
! 	else if (COMPLETE_TYPE_P (TREE_TYPE (decl)))
  	  {
  	    /* A complete type is ok if size is fixed.  */
  
*************** start_decl (declarator, declspecs, initi
*** 3593,3599 ****
        && DECL_RTL (tem) == 0
        && !DECL_CONTEXT (tem))
      {
!       if (COMPLETE_TYPE_P (TREE_TYPE (tem)))
  	expand_decl (tem);
        else if (TREE_CODE (TREE_TYPE (tem)) == ARRAY_TYPE
  	       && DECL_INITIAL (tem) != 0)
--- 3598,3605 ----
        && DECL_RTL (tem) == 0
        && !DECL_CONTEXT (tem))
      {
!       if (TREE_TYPE (tem) != error_mark_node
! 	  && COMPLETE_TYPE_P (TREE_TYPE (tem)))
  	expand_decl (tem);
        else if (TREE_CODE (TREE_TYPE (tem)) == ARRAY_TYPE
  	       && DECL_INITIAL (tem) != 0)
*************** finish_decl (decl, init, asmspec_tree)
*** 3688,3697 ****
  
    if (TREE_CODE (decl) == VAR_DECL)
      {
!       if (DECL_SIZE (decl) == 0 && COMPLETE_TYPE_P (TREE_TYPE (decl)))
  	layout_decl (decl, 0);
  
        if (DECL_SIZE (decl) == 0
  	  && (TREE_STATIC (decl)
  	      ?
  		/* A static variable with an incomplete type
--- 3694,3706 ----
  
    if (TREE_CODE (decl) == VAR_DECL)
      {
!       if (DECL_SIZE (decl) == 0 && TREE_TYPE (decl) != error_mark_node
! 	  && COMPLETE_TYPE_P (TREE_TYPE (decl)))
  	layout_decl (decl, 0);
  
        if (DECL_SIZE (decl) == 0
+ 	  /* Don't give an error if we already gave one earlier.  */
+ 	  && TREE_TYPE (decl) != error_mark_node
  	  && (TREE_STATIC (decl)
  	      ?
  		/* A static variable with an incomplete type


More information about the Gcc-patches mailing list