flexible array members and initialization thereof

Richard Henderson rth@redhat.com
Sun Nov 19 17:41:00 GMT 2000


> 	* c-decl.c (grokdeclarator): Support flexible array members.
> 	Use open-ended ranges for these and zero-length arrays.
> 	* c-typeck.c (push_init_level): Validate the context of
> 	initialization of a zero-length array.
> 	* tree.c (int_fits_type_p): Be prepared for missing bounds.
> 	* varasm.c (array_size_for_constructor): New.
> 	(output_constructor): Use it for arrays of unspecified length.
> 	* extend.texi (Zero Length): Mention C99 flexible array members.
> 	Document initialization in a top-level struct as valid.

Ho hum.  Problem 1: I should have tried those test cases with
debugging turned on.


r~


        * dwarf2out.c (simple_type_size_in_bits): Handle a type with
        no computed size as size zero.
        (field_byte_offset): Likewise.

Index: dwarf2out.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/dwarf2out.c,v
retrieving revision 1.220
diff -c -p -d -r1.220 dwarf2out.c
*** dwarf2out.c	2000/11/19 13:15:50	1.220
--- dwarf2out.c	2000/11/20 01:23:51
*************** static inline unsigned HOST_WIDE_INT
*** 7790,7806 ****
  simple_type_size_in_bits (type)
       register tree type;
  {
    if (TREE_CODE (type) == ERROR_MARK)
      return BITS_PER_WORD;
!   else
!     {
!       register tree type_size_tree = TYPE_SIZE (type);
! 
!       if (! host_integerp (type_size_tree, 1))
! 	return TYPE_ALIGN (type);
  
!       return tree_low_cst (type_size_tree, 1);
!     }
  }
  
  /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
--- 7790,7806 ----
  simple_type_size_in_bits (type)
       register tree type;
  {
+   tree type_size_tree;
+ 
    if (TREE_CODE (type) == ERROR_MARK)
      return BITS_PER_WORD;
!   type_size_tree = TYPE_SIZE (type);
  
!   if (type_size_tree == NULL_TREE)
!     return 0;
!   if (! host_integerp (type_size_tree, 1))
!     return TYPE_ALIGN (type);
!   return tree_low_cst (type_size_tree, 1);
  }
  
  /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
*************** field_byte_offset (decl)
*** 7835,7848 ****
    type = field_type (decl);
    field_size_tree = DECL_SIZE (decl);
  
!   /* If there was an error, the size could be zero.  */
    if (! field_size_tree)
!     {
!       if (errorcount)
! 	return 0;
! 
!       abort ();
!     }
  
    /* We cannot yet cope with fields whose positions are variable, so
       for now, when we see such things, we simply return 0.  Someday, we may
--- 7835,7844 ----
    type = field_type (decl);
    field_size_tree = DECL_SIZE (decl);
  
!   /* The size could be unspecified if there was an error, or for
!      a flexible array member.  */
    if (! field_size_tree)
!     field_size_tree = bitsize_zero_node;
  
    /* We cannot yet cope with fields whose positions are variable, so
       for now, when we see such things, we simply return 0.  Someday, we may
*************** field_byte_offset (decl)
*** 7852,7858 ****
  
    bitpos_int = int_bit_position (decl);
  
!     /* If we don't know the size of the field, pretend it's a full word.  */
    if (host_integerp (field_size_tree, 1))
      field_size_in_bits = tree_low_cst (field_size_tree, 1);
    else
--- 7848,7854 ----
  
    bitpos_int = int_bit_position (decl);
  
!   /* If we don't know the size of the field, pretend it's a full word.  */
    if (host_integerp (field_size_tree, 1))
      field_size_in_bits = tree_low_cst (field_size_tree, 1);
    else


More information about the Gcc-patches mailing list