public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/33535]  New: bitpos_of_field() returns false result base of hard coded multiplication by 8
@ 2007-09-23  8:44 tomerben at ceva-dsp dot com
  2007-09-23 11:04 ` [Bug tree-optimization/33535] " rguenth at gcc dot gnu dot org
  2007-09-23 16:32 ` tomerben at ceva-dsp dot com
  0 siblings, 2 replies; 3+ messages in thread
From: tomerben at ceva-dsp dot com @ 2007-09-23  8:44 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug tree-optimization/33535] bitpos_of_field() returns false result base of hard coded multiplication by 8
  2007-09-23  8:44 [Bug tree-optimization/33535] New: bitpos_of_field() returns false result base of hard coded multiplication by 8 tomerben at ceva-dsp dot com
@ 2007-09-23 11:04 ` rguenth at gcc dot gnu dot org
  2007-09-23 16:32 ` tomerben at ceva-dsp dot com
  1 sibling, 0 replies; 3+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2007-09-23 11:04 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from rguenth at gcc dot gnu dot org  2007-09-23 11:04 -------
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)


-- 


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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug tree-optimization/33535] bitpos_of_field() returns false result base of hard coded multiplication by 8
  2007-09-23  8:44 [Bug tree-optimization/33535] New: bitpos_of_field() returns false result base of hard coded multiplication by 8 tomerben at ceva-dsp dot com
  2007-09-23 11:04 ` [Bug tree-optimization/33535] " rguenth at gcc dot gnu dot org
@ 2007-09-23 16:32 ` tomerben at ceva-dsp dot com
  1 sibling, 0 replies; 3+ messages in thread
From: tomerben at ceva-dsp dot com @ 2007-09-23 16:32 UTC (permalink / raw)
  To: gcc-bugs



------- 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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2007-09-23 16:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-09-23  8:44 [Bug tree-optimization/33535] New: bitpos_of_field() returns false result base of hard coded multiplication by 8 tomerben at ceva-dsp dot com
2007-09-23 11:04 ` [Bug tree-optimization/33535] " rguenth at gcc dot gnu dot org
2007-09-23 16:32 ` tomerben at ceva-dsp dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).