PATCH: fix tree-check violations for C++

Greg McGary gkm@eng.ascend.com
Tue Oct 5 12:26:00 GMT 1999


Jason Merrill <jason@cygnus.com> writes:

> >>>>> Greg McGary <gkm@eng.ascend.com> writes:
> 
>  > diff -u -p -r1.189 class.c
> 
> Please use diff -c -p for significant changes; diff -u becomes unreadable
> very quickly.
> 
>  > +  /* Delete all zero-width bit-fields from the fieldlist */
>  > +  {
>  > +    tree *fieldsp = &fields;
>  > +    while (*fieldsp && TREE_CODE (*fieldsp) == FIELD_DECL)
>  > +      if (DECL_C_BIT_FIELD (*fieldsp) && DECL_INITIAL (*fieldsp))
>  > +	*fieldsp = TREE_CHAIN (*fieldsp);
>  >        else
>  > +	fieldsp = &TREE_CHAIN (*fieldsp);
>  > +  }
>  >    TYPE_FIELDS (t) = fields;
> 
> This is wrong; the loop will stop when it hits the first non-FIELD_DECL.
> The TREE_CODE check should be in the if.

OK.  Here's a revised patch:

Index: c-decl.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/c-decl.c,v
retrieving revision 1.82
diff -p -c -r1.82 c-decl.c
*** c-decl.c	1999/09/30 13:40:41	1.82
--- c-decl.c	1999/10/05 18:34:45
*************** finish_struct (t, fieldlist, attributes)
*** 5526,5542 ****
  
    layout_type (t);
  
!   /* Delete all zero-width bit-fields from the front of the fieldlist */
!   while (fieldlist
! 	 && DECL_INITIAL (fieldlist))
!     fieldlist = TREE_CHAIN (fieldlist);
!   /* Delete all such members from the rest of the fieldlist */
!   for (x = fieldlist; x;)
!     {
!       if (TREE_CHAIN (x) && DECL_INITIAL (TREE_CHAIN (x)))
! 	TREE_CHAIN (x) = TREE_CHAIN (TREE_CHAIN (x));
!       else x = TREE_CHAIN (x);
!     }
  
    /*  Now we have the truly final field list.
        Store it in this type and in the variants.  */
--- 5526,5540 ----
  
    layout_type (t);
  
!   /* Delete all zero-width bit-fields from the fieldlist */
!   {
!     tree *fieldlistp = &fieldlist;
!     while (*fieldlistp)
!       if (TREE_CODE (*fieldlistp) == FIELD_DECL && DECL_INITIAL (*fieldlistp))
! 	*fieldlistp = TREE_CHAIN (*fieldlistp);
!       else
! 	fieldlistp = &TREE_CHAIN (*fieldlistp);
!   }
  
    /*  Now we have the truly final field list.
        Store it in this type and in the variants.  */
Index: cp/class.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/class.c,v
retrieving revision 1.189
diff -p -c -r1.189 class.c
*** class.c	1999/09/29 22:52:49	1.189
--- class.c	1999/10/05 18:34:55
*************** finish_struct_1 (t)
*** 3860,3878 ****
  
    my_friendly_assert (TYPE_FIELDS (t) == fields, 981117);
  
!   /* Delete all zero-width bit-fields from the front of the fieldlist */
!   while (fields && DECL_C_BIT_FIELD (fields)
! 	 && DECL_INITIAL (fields))
!     fields = TREE_CHAIN (fields);
!   /* Delete all such fields from the rest of the fields.  */
!   for (x = fields; x;)
!     {
!       if (TREE_CHAIN (x) && DECL_C_BIT_FIELD (TREE_CHAIN (x))
! 	  && DECL_INITIAL (TREE_CHAIN (x)))
! 	TREE_CHAIN (x) = TREE_CHAIN (TREE_CHAIN (x));
        else
! 	x = TREE_CHAIN (x);
!     }
    TYPE_FIELDS (t) = fields;
  
    if (TYPE_USES_VIRTUAL_BASECLASSES (t))
--- 3860,3875 ----
  
    my_friendly_assert (TYPE_FIELDS (t) == fields, 981117);
  
!   /* Delete all zero-width bit-fields from the fieldlist */
!   {
!     tree *fieldsp = &fields;
!     while (*fieldsp)
!       if (TREE_CODE (*fieldsp) == FIELD_DECL
! 	  && DECL_C_BIT_FIELD (*fieldsp) && DECL_INITIAL (*fieldsp))
! 	*fieldsp = TREE_CHAIN (*fieldsp);
        else
! 	fieldsp = &TREE_CHAIN (*fieldsp);
!   }
    TYPE_FIELDS (t) = fields;
  
    if (TYPE_USES_VIRTUAL_BASECLASSES (t))
Index: cp/decl2.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/decl2.c,v
retrieving revision 1.272
diff -p -c -r1.272 decl2.c
*** decl2.c	1999/10/01 00:43:27	1.272
--- decl2.c	1999/10/05 18:35:08
*************** mark_used (decl)
*** 5157,5163 ****
       if it's a partial instantiation, but there's no need to
       instantiate such a thing.  We check that DECL is not an explicit
       instantiation because that is not checked in instantiate_decl.  */
!   if (TREE_CODE (decl) != TEMPLATE_DECL
        && DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl)
        && !DECL_EXPLICIT_INSTANTIATION (decl))
      instantiate_decl (decl);
--- 5157,5163 ----
       if it's a partial instantiation, but there's no need to
       instantiate such a thing.  We check that DECL is not an explicit
       instantiation because that is not checked in instantiate_decl.  */
!   if (TREE_CODE (decl) != TEMPLATE_DECL && TREE_CODE (decl) != CONST_DECL
        && DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl)
        && !DECL_EXPLICIT_INSTANTIATION (decl))
      instantiate_decl (decl);


More information about the Gcc-patches mailing list