This is the mail archive of the gcc-bugs@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]

[Bug c/3325] cast of bit-field to same type gets discarded


------- Additional Comments From jsm at polyomino dot org dot uk  2004-01-21 17:59 -------
Subject: Re:  cast of bit-field to same type gets discarded

On Wed, 21 Jan 2004, schwab at suse dot de wrote:

> Can this be fixed in 3.4? 

I very much doubt a patch for it could fail to be too destabilising for a
release branch; in any case, this isn't a regression.  I attempted a
resurrection of the patch and found it needed changes to expand_expr
<http://gcc.gnu.org/ml/gcc-patches/2003-12/msg00651.html> (though no
experts thereon commented on the proper approach); I didn't get a patch to
expand_expr as far as passing both bootstrap/regression tests and all of
the tests below.  I didn't get as far as looking at the debug info
problems with the original patch (the ABI issues were, however, fixed, by
using the declared type when layout was done and adjusting the type to the
bit-field type later).

Note: I don't suppose the original patch passed all the tests below
either, given the need for middle-end support for the bit-field types.  
But presumably it didn't fail the existing regression tests which showed
up the need for middle-end changes, and subsequent C front end changes may
have caused this issue to show up now.

Note: We should also look again at how bool bit-fields work in the light
of the recent dicussion on the WG14 reflector, though I don't think that
reached a clear consensus.

/* Test that operations on bit-fields yield results reduced to bit-field
   type.  */
/* Origin: Joseph Myers <jsm@polyomino.org.uk> */

extern void exit (int);
extern void abort (void);

struct s {
  unsigned long long u33: 33;
  unsigned long long u40: 40;
  unsigned long long u41: 41;
};

struct s a = { 0x100000, 0x100000, 0x100000 };
struct s b = { 0x100000000ULL, 0x100000000ULL, 0x100000000ULL };
struct s c = { 0x1FFFFFFFFULL, 0, 0 };

int 
main (void)
{
  if (a.u33 * a.u33 != 0 || a.u33 * a.u40 != 0 || a.u40 * a.u33 != 0
      || a.u40 * a.u40 != 0)
    abort ();
  if (a.u33 * a.u41 != 0x10000000000ULL
      || a.u40 * a.u41 != 0x10000000000ULL
      || a.u41 * a.u33 != 0x10000000000ULL
      || a.u41 * a.u40 != 0x10000000000ULL
      || a.u41 * a.u41 != 0x10000000000ULL)
    abort ();
  if (b.u33 + b.u33 != 0)
    abort ();
  if (b.u33 + b.u40 != 0x200000000ULL
      || b.u33 + b.u41 != 0x200000000ULL
      || b.u40 + b.u33 != 0x200000000ULL
      || b.u40 + b.u40 != 0x200000000ULL
      || b.u40 + b.u41 != 0x200000000ULL
      || b.u41 + b.u33 != 0x200000000ULL
      || b.u41 + b.u40 != 0x200000000ULL
      || b.u41 + b.u41 != 0x200000000ULL)
    abort ();
  if (a.u33 - b.u33 != 0x100100000ULL
      || a.u33 - b.u40 != 0xFF00100000ULL
      || a.u33 - b.u41 != 0x1FF00100000ULL
      || a.u40 - b.u33 != 0xFF00100000ULL
      || a.u40 - b.u40 != 0xFF00100000ULL
      || a.u40 - b.u41 != 0x1FF00100000ULL
      || a.u41 - b.u33 != 0x1FF00100000ULL
      || a.u41 - b.u40 != 0x1FF00100000ULL
      || a.u41 - b.u41 != 0x1FF00100000ULL)
    abort ();
  if (++c.u33 != 0 || --c.u40 != 0xFFFFFFFFFFULL || c.u41-- != 0)
    abort ();
  exit (0);
}



-- 


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


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