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]

RFC: add constant offset to bit_offset in get_inner_reference


In get_inner_reference in expr.c, an integer constant (as defined by
host_integerp) offset can be added to OFFSET rather than BIT_OFFSET.
Most of the time, this is resolved later in get_inner_reference, where
a integer constant OFFSET is converted to a bit offset and added to
BIT_OFFSET.

However, if OFFSET already contains a variable offset, the integer
constant offset added to OFFSET will go unnoticed.  To improve this,
would the patch below be acceptable?

diff -c -9 -p -r1.418 expr.c
*************** get_inner_reference (exp, pbitsize, pbit
    while (1)
      {
	if (TREE_CODE (exp) == BIT_FIELD_REF)
	  bit_offset = size_binop (PLUS_EXPR, bit_offset, TREE_OPERAND (exp, 2));
	else if (TREE_CODE (exp) == COMPONENT_REF)
	  {
	    tree field = TREE_OPERAND (exp, 1);
	    tree this_offset = DECL_FIELD_OFFSET (field);
  
  	  /* If this field hasn't been filled in yet, don't go
  	     past it.  This should only happen when folding expressions
  	     made during type construction.  */
  	  if (this_offset == 0)
  	    break;
  	  else if (! TREE_CONSTANT (this_offset)
  		   && contains_placeholder_p (this_offset))
  	    this_offset = build (WITH_RECORD_EXPR, sizetype, this_offset, exp);
  
+ 	  /* If the offset is an integer constant, fold it
+              into bit_offset.  */
+ 	  if (host_integerp (this_offset, 0))
+ 	    {
+ 	      tree this_bit_offset = size_binop (MULT_EXPR,
+ 						 bitsize_unit_node,
+ 						 convert (bitsizetype,
+ 							  this_offset));
+ 	      bit_offset = size_binop (PLUS_EXPR, bit_offset, this_bit_offset);
+ 	      this_offset = size_zero_node;
+ 	      /* FIXME: is this right?  */
+ 	      this_offset = build (WITH_RECORD_EXPR, sizetype, this_offset,
+ 				   exp);
+ 	    }
+ 
  	  offset = size_binop (PLUS_EXPR, offset, this_offset);
  	  bit_offset = size_binop (PLUS_EXPR, bit_offset,
  				   DECL_FIELD_BIT_OFFSET (field));
  
  	  /* ??? Right now we don't do anything with DECL_OFFSET_ALIGN.  */
  	}
  
        else if (TREE_CODE (exp) == ARRAY_REF


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