[Bug tree-optimization/33535] New: bitpos_of_field() returns false result base of hard coded multiplication by 8

2007-09-23 Thread tomerben at ceva-dsp dot com
Taken from tree-ssa-structalias.c:
The original code:

static unsigned HOST_WIDE_INT
bitpos_of_field (const tree fdecl)
{

  if (TREE_CODE (DECL_FIELD_OFFSET (fdecl)) != INTEGER_CST
  || TREE_CODE (DECL_FIELD_BIT_OFFSET (fdecl)) != INTEGER_CST)
return -1;

  return (tree_low_cst (DECL_FIELD_OFFSET (fdecl), 1) * 8) 
+ tree_low_cst (DECL_FIELD_BIT_OFFSET (fdecl), 1);
}

I think the code needs to be:

static unsigned HOST_WIDE_INT
bitpos_of_field (const tree fdecl)
{

  if (TREE_CODE (DECL_FIELD_OFFSET (fdecl)) != INTEGER_CST
  || TREE_CODE (DECL_FIELD_BIT_OFFSET (fdecl)) != INTEGER_CST)
return -1;

  return (tree_low_cst (DECL_FIELD_OFFSET (fdecl), 1) * BITS_PER_UNIT) 
 + tree_low_cst (DECL_FIELD_BIT_OFFSET (fdecl), 1);
}

The offset in bits need to consider the BITS_PER_UNIT macro instead of hard
coded 8. This is usefull for machines that have different value of
BITS_PER_UNIT (16 for e.g. on the port I'm working on).


-- 
   Summary: bitpos_of_field() returns false result base of hard
coded multiplication by 8
   Product: gcc
   Version: 4.2.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: tree-optimization
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: tomerben at ceva-dsp dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33535



[Bug tree-optimization/33535] bitpos_of_field() returns false result base of hard coded multiplication by 8

2007-09-23 Thread tomerben at ceva-dsp dot com


--- Comment #2 from tomerben at ceva-dsp dot com  2007-09-23 16:31 ---
(In reply to comment #1)
> If so (did you look how DECL_FIELD_OFFSET is set?) then the documentation in
> tree.h needs adjustment as well:
> /* In a FIELD_DECL, this is the field position, counting in bytes, of the
>DECL_OFFSET_ALIGN-bit-sized word containing the bit closest to the 
> beginning
>of the structure.  */
> #define DECL_FIELD_OFFSET(NODE) (FIELD_DECL_CHECK (NODE)->field_decl.offset)

I don't think the documentation needs to be modified - multiplying the offset
in bytes (=units) by the BITS_PER_UNIT makes perfect sense to get the bitpos of
a certain field.

taken from the gcc internals:
"BITS_PER_UNIT [Macro]- Define this macro to be the number of bits in an
addressable storage unit (byte). If you do not define this macro the default is
8."

In most cases unit=byte=8 but in my case unit=byte=16 and hard coded
multiplication by 8 is wrong.


-- 

tomerben at ceva-dsp dot com changed:

   What|Removed |Added

     CC|                |tomerben at ceva-dsp dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33535