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]

Minor cleanups in stor-layout.c


While I was looking at other things, I noticed a whole bunch of whitespace
errors in the MS-bitfields stuff along with some incorrect typing of 
variables and explicit uses of TREE_INT_CST_LOW, which is now discouraged.
I fixed other similar errors in other places.

Tested on i686-pc-linux-gnu.

Tue Apr 29 18:50:52 2003  Richard Kenner  <kenner@vlsi1.ultra.nyu.edu>

	* stor-layout.c (mode_for_size_tree): Use tree_low_cst.
	(layout_decl, place_field): Likewise.
	Also make minor type and whitespace changes.

*** gcc/stor-layout.c	21 Apr 2003 20:43:21 -0000	1.152
--- gcc/stor-layout.c	29 Apr 2003 22:44:53 -0000
*************** mode_for_size_tree (size, class, limit)
*** 250,254 ****
      return BLKmode;
    else
!     return mode_for_size (TREE_INT_CST_LOW (size), class, limit);
  }
  
--- 250,254 ----
      return BLKmode;
    else
!     return mode_for_size (tree_low_cst (size, 1), class, limit);
  }
  
*************** layout_decl (decl, known_align)
*** 534,538 ****
  	  && compare_tree_int (size, larger_than_size) > 0)
  	{
! 	  unsigned int size_as_int = TREE_INT_CST_LOW (size);
  
  	  if (compare_tree_int (size, size_as_int) == 0)
--- 534,538 ----
  	  && compare_tree_int (size, larger_than_size) > 0)
  	{
! 	  int size_as_int = TREE_INT_CST_LOW (size);
  
  	  if (compare_tree_int (size, size_as_int) == 0)
*************** place_field (rli, field)
*** 1075,1086 ****
  	      && !integer_zerop (DECL_SIZE (field))
  	      && !integer_zerop (DECL_SIZE (rli->prev_field))
  	      && simple_cst_equal (TYPE_SIZE (type),
! 		   TYPE_SIZE (TREE_TYPE (rli->prev_field))) )
  	    {
  	      /* We're in the middle of a run of equal type size fields; make
  		 sure we realign if we run out of bits.  (Not decl size,
  		 type size!) */
! 	      int bitsize = TREE_INT_CST_LOW (DECL_SIZE (field));
! 	      tree type_size = TYPE_SIZE(TREE_TYPE(rli->prev_field));
  
  	      if (rli->remaining_in_alignment < bitsize)
--- 1075,1087 ----
  	      && !integer_zerop (DECL_SIZE (field))
  	      && !integer_zerop (DECL_SIZE (rli->prev_field))
+ 	      && host_integerp (DECL_SIZE (rli->prev_field), 0)
+ 	      && host_integerp (TYPE_SIZE (type), 0)
  	      && simple_cst_equal (TYPE_SIZE (type),
! 				   TYPE_SIZE (TREE_TYPE (rli->prev_field))))
  	    {
  	      /* We're in the middle of a run of equal type size fields; make
  		 sure we realign if we run out of bits.  (Not decl size,
  		 type size!) */
! 	      HOST_WIDE_INT bitsize = tree_low_cst (DECL_SIZE (field), 0);
  
  	      if (rli->remaining_in_alignment < bitsize)
*************** place_field (rli, field)
*** 1088,1097 ****
  		  /* out of bits; bump up to next 'word'.  */
  		  rli->offset = DECL_FIELD_OFFSET (rli->prev_field);
! 		  rli->bitpos = size_binop (PLUS_EXPR,
! 				      type_size,
! 				      DECL_FIELD_BIT_OFFSET(rli->prev_field));
  		  rli->prev_field = field;
! 		  rli->remaining_in_alignment = TREE_INT_CST_LOW (type_size);
  		}
  	      rli->remaining_in_alignment -= bitsize;
  	    }
--- 1089,1100 ----
  		  /* out of bits; bump up to next 'word'.  */
  		  rli->offset = DECL_FIELD_OFFSET (rli->prev_field);
! 		  rli->bitpos
! 		    = size_binop (PLUS_EXPR, TYPE_SIZE (type),
! 				  DECL_FIELD_BIT_OFFSET (rli->prev_field));
  		  rli->prev_field = field;
! 		  rli->remaining_in_alignment
! 		    = tree_low_cst (TYPE_SIZE (type), 0);
  		}
+ 
  	      rli->remaining_in_alignment -= bitsize;
  	    }
*************** place_field (rli, field)
*** 1109,1123 ****
  	      if (!integer_zerop (DECL_SIZE (rli->prev_field)))
  		{
! 		  tree type_size = TYPE_SIZE(TREE_TYPE(rli->prev_field));
! 		  rli->bitpos = size_binop (PLUS_EXPR,
! 				      type_size,
! 				      DECL_FIELD_BIT_OFFSET(rli->prev_field));
  		}
  	      else
! 		{
! 		  /* We "use up" size zero fields; the code below should behave
! 		     as if the prior field was not a bitfield.  */
! 		  prev_saved = NULL;
! 		}
  
  	      /* Cause a new bitfield to be captured, either this time (if
--- 1112,1125 ----
  	      if (!integer_zerop (DECL_SIZE (rli->prev_field)))
  		{
! 		  tree type_size = TYPE_SIZE (TREE_TYPE (rli->prev_field));
! 
! 		  rli->bitpos
! 		    = size_binop (PLUS_EXPR, type_size,
! 				  DECL_FIELD_BIT_OFFSET (rli->prev_field));
  		}
  	      else
! 		/* We "use up" size zero fields; the code below should behave
! 		   as if the prior field was not a bitfield.  */
! 		prev_saved = NULL;
  
  	      /* Cause a new bitfield to be captured, either this time (if
*************** place_field (rli, field)
*** 1125,1132 ****
  	      if (!DECL_BIT_FIELD_TYPE(field)
  		 || integer_zerop (DECL_SIZE (field)))
! 		{
! 		  rli->prev_field = NULL;
! 		}
  	    }
  	  normalize_rli (rli);
          }
--- 1127,1133 ----
  	      if (!DECL_BIT_FIELD_TYPE(field)
  		 || integer_zerop (DECL_SIZE (field)))
! 		rli->prev_field = NULL;
  	    }
+ 
  	  normalize_rli (rli);
          }
*************** place_field (rli, field)
*** 1147,1154 ****
  	  || ( prev_saved != NULL
  	       ? !simple_cst_equal (TYPE_SIZE (type),
! 	              TYPE_SIZE (TREE_TYPE (prev_saved)))
! 	       : !integer_zerop (DECL_SIZE (field)) ))
  	{
! 	  unsigned int type_align = 8;  /* Never below 8 for compatibility */
  
  	  /* (When not a bitfield), we could be seeing a flex array (with
--- 1148,1156 ----
  	  || ( prev_saved != NULL
  	       ? !simple_cst_equal (TYPE_SIZE (type),
! 				    TYPE_SIZE (TREE_TYPE (prev_saved)))
! 	      : !integer_zerop (DECL_SIZE (field)) ))
  	{
! 	  /* Never smaller than a byte for compatibility.  */
! 	  unsigned int type_align = BITS_PER_UNIT;
  
  	  /* (When not a bitfield), we could be seeing a flex array (with
*************** place_field (rli, field)
*** 1156,1168 ****
  	     until we see a bitfield (and come by here again) we just skip
  	     calculating it.  */
! 
! 	  if (DECL_SIZE (field) != NULL)
! 	      rli->remaining_in_alignment
! 		  = TREE_INT_CST_LOW (TYPE_SIZE(TREE_TYPE(field)))
! 		    - TREE_INT_CST_LOW (DECL_SIZE (field));
  
  	  /* Now align (conventionally) for the new type.  */
  	  if (!DECL_PACKED(field))
! 	      type_align = MAX(TYPE_ALIGN (type), type_align);
  
  	  if (prev_saved
--- 1158,1171 ----
  	     until we see a bitfield (and come by here again) we just skip
  	     calculating it.  */
! 	  if (DECL_SIZE (field) != NULL
! 	      && host_integerp (TYPE_SIZE (TREE_TYPE (field)), 0)
! 	      && host_integerp (DECL_SIZE (field), 0))
! 	    rli->remaining_in_alignment
! 	      = tree_low_cst (TYPE_SIZE (TREE_TYPE(field)), 0)
! 		- tree_low_cst (DECL_SIZE (field), 0);
  
  	  /* Now align (conventionally) for the new type.  */
  	  if (!DECL_PACKED(field))
! 	    type_align = MAX(TYPE_ALIGN (type), type_align);
  
  	  if (prev_saved
*************** place_field (rli, field)
*** 1179,1182 ****
--- 1182,1186 ----
  
  	  rli->bitpos = round_up (rli->bitpos, type_align);
+ 
            /* If we really aligned, don't allow subsequent bitfields
  	     to undo that.  */
*************** layout_type (type)
*** 1861,1868 ****
  	  unsigned int alignment
  	    = set_alignment ? set_alignment : SET_WORD_SIZE;
! 	  int size_in_bits
! 	    = (TREE_INT_CST_LOW (TYPE_MAX_VALUE (TYPE_DOMAIN (type)))
! 	       - TREE_INT_CST_LOW (TYPE_MIN_VALUE (TYPE_DOMAIN (type))) + 1);
! 	  int rounded_size
  	    = ((size_in_bits + alignment - 1) / alignment) * alignment;
  
--- 1865,1872 ----
  	  unsigned int alignment
  	    = set_alignment ? set_alignment : SET_WORD_SIZE;
! 	  HOST_WIDE_INT size_in_bits
! 	    = (tree_low_cst (TYPE_MAX_VALUE (TYPE_DOMAIN (type)), 0)
! 	       - tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0) + 1);
! 	  HOST_WIDE_INT rounded_size
  	    = ((size_in_bits + alignment - 1) / alignment) * alignment;
  


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