public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/14786] New: Struct misaligned containing unsigned char bit-field
@ 2004-03-30 19:13 ryanma at cpsc dot ucalgary dot ca
  2004-03-30 19:36 ` [Bug c/14786] " pinskia at gcc dot gnu dot org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: ryanma at cpsc dot ucalgary dot ca @ 2004-03-30 19:13 UTC (permalink / raw)
  To: gcc-bugs

Description:

According to RS/6000 Alignment Rules, structs containing   
bit fields are 4-byte (word) aligned. The following testcase 
illustrates that this rule is violated, when Substruct B is not  
word aligned. 

Testcase:

extern int      printf(const char *, ...);
typedef unsigned char UCHAR;

typedef struct {
    UCHAR               a   : 1 ;
    UCHAR               b   : 1 ;
    UCHAR               c   : 1 ;
    UCHAR               d   : 1 ;
    UCHAR               e   : 1 ;
    UCHAR               f   : 1 ;
    UCHAR               g   : 1 ;
    UCHAR               h   : 1 ;
    UCHAR               i   : 1 ;
    UCHAR               J   : 1 ;
    UCHAR               K   : 6 ;
} SubStruct ;

typedef struct {
    UCHAR               A[5];
    SubStruct           B   ;
    UCHAR               C   ;
    UCHAR               D[4];
} Struct ;

int main() {
  Struct data;
  printf("sizeof(SubStruct) =%d\n",sizeof(SubStruct));
  printf("sizeof(Struct)    =%d\n",sizeof(Struct));
  printf(" offset of B      =%d\n",
        ((unsigned int)&(data.B)-(unsigned int)&data));
  printf(" offset of C      =%d\n",
        ((unsigned int)&(data.C)-(unsigned int)&data));
  printf(" offset of D      =%d\n",
        ((unsigned int)&(data.D)-(unsigned int)&data));
  return 0;
}

Actual Output:

$ gcc t.c
$ ./a.out
Address of Struct =2ff22a20
sizeof(SubStruct) =2
sizeof(Struct)    =12
 offset of B      =5
 offset of C      =7
 offset of D      =8
$

Expected Output:

$ gcc t.c
$ ./a.out
Address of Struct =2ff22a20
sizeof(SubStruct) =2
sizeof(Struct)    =20
 offset of B      =8
 offset of C      =12
 offset of D      =13


GCC Version:

$ /home/ryan/gcc-3.3.2/aix51/bin/gcc -v
Reading specs from /home/ryan/gcc-3.3.2/aix51/bin/../lib/gcc-lib/powerpc-ibm-
aix5.1.0.0/3.3.
2/specs
Configured with: ../gcc-3.3.2/configure --disable-nls
Thread model: aix
gcc version 3.3.2

Machine Type:

Model: 7044 -170
Processor: 1 x pwr3 
Processor Speed: 400 MHz
Memory: 1 GB
AIX Level: AIX 5.1 ML 5
Hardware Arch: 64 bit
Kernel Arch: 32 bit

-- 
           Summary: Struct misaligned containing unsigned char bit-field
           Product: gcc
           Version: 3.3.2
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: ryanma at cpsc dot ucalgary dot ca
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: powerpc-ibm-aix5.1.0.0
  GCC host triplet: powerpc-ibm-aix5.1.0.0
GCC target triplet: powerpc-ibm-aix5.1.0.0


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


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

* [Bug c/14786] Struct misaligned containing unsigned char bit-field
  2004-03-30 19:13 [Bug c/14786] New: Struct misaligned containing unsigned char bit-field ryanma at cpsc dot ucalgary dot ca
@ 2004-03-30 19:36 ` pinskia at gcc dot gnu dot org
  2004-03-31 15:35 ` ryanma at cpsc dot ucalgary dot ca
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-03-30 19:36 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-03-30 19:36 -------
>From Mac OS PEF ABI which is based on the PowerOpen ABI which is the ABI for AIX:
The preferred alignment of a bit field is the same as its declared type.

So if the same wording is in the Power Open ABI then this is invalid as it is correctly aligned and bit-
fields are aligned as the same as their declared type.

-- 


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


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

* [Bug c/14786] Struct misaligned containing unsigned char bit-field
  2004-03-30 19:13 [Bug c/14786] New: Struct misaligned containing unsigned char bit-field ryanma at cpsc dot ucalgary dot ca
  2004-03-30 19:36 ` [Bug c/14786] " pinskia at gcc dot gnu dot org
@ 2004-03-31 15:35 ` ryanma at cpsc dot ucalgary dot ca
  2004-04-04  6:38 ` [Bug target/14786] " pinskia at gcc dot gnu dot org
  2004-06-03 22:50 ` pinskia at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: ryanma at cpsc dot ucalgary dot ca @ 2004-03-31 15:35 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From ryanma at cpsc dot ucalgary dot ca  2004-03-31 15:35 -------
http://publib.boulder.ibm.com/infocenter/comphelp/topic/com.ibm.vacpp6a.doc/prog
uide/ref/rvclralg.htm

The xlc compiler exhibits the expected behavior.

$ xlc t.c -qlanglvl=extended
"t.c", line 5.25: 1506-159 (E) Bit-field type specified for a is not valid. 
Type unsigned assumed.
"t.c", line 6.25: 1506-159 (E) Bit-field type specified for b is not valid. 
Type unsigned assumed.
"t.c", line 7.25: 1506-159 (E) Bit-field type specified for c is not valid. 
Type unsigned assumed.
"t.c", line 8.25: 1506-159 (E) Bit-field type specified for d is not valid. 
Type unsigned assumed.
"t.c", line 9.25: 1506-159 (E) Bit-field type specified for e is not valid. 
Type unsigned assumed.
"t.c", line 10.25: 1506-159 (E) Bit-field type specified for f is not valid. 
Type unsigned assumed.
"t.c", line 11.25: 1506-159 (E) Bit-field type specified for g is not valid. 
Type unsigned assumed.
"t.c", line 12.25: 1506-159 (E) Bit-field type specified for h is not valid. 
Type unsigned assumed.
"t.c", line 13.25: 1506-159 (E) Bit-field type specified for i is not valid. 
Type unsigned assumed.
"t.c", line 14.25: 1506-159 (E) Bit-field type specified for J is not valid. 
Type unsigned assumed.
"t.c", line 15.25: 1506-159 (E) Bit-field type specified for K is not valid. 
Type unsigned assumed.
./a.out
$ ./a.out
Address of Struct =2ff22a20
sizeof(SubStruct) =4
sizeof(Struct)    =20
 offset of B      =8
 offset of C      =12
 offset of D      =13


-- 


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


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

* [Bug target/14786] Struct misaligned containing unsigned char bit-field
  2004-03-30 19:13 [Bug c/14786] New: Struct misaligned containing unsigned char bit-field ryanma at cpsc dot ucalgary dot ca
  2004-03-30 19:36 ` [Bug c/14786] " pinskia at gcc dot gnu dot org
  2004-03-31 15:35 ` ryanma at cpsc dot ucalgary dot ca
@ 2004-04-04  6:38 ` pinskia at gcc dot gnu dot org
  2004-06-03 22:50 ` pinskia at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-04-04  6:38 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-04-04 06:37 -------
Note in OpenPower ABI, bitfields are only defined for short and int.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|c                           |target
           Keywords|                            |ABI, wrong-code


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


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

* [Bug target/14786] Struct misaligned containing unsigned char bit-field
  2004-03-30 19:13 [Bug c/14786] New: Struct misaligned containing unsigned char bit-field ryanma at cpsc dot ucalgary dot ca
                   ` (2 preceding siblings ...)
  2004-04-04  6:38 ` [Bug target/14786] " pinskia at gcc dot gnu dot org
@ 2004-06-03 22:50 ` pinskia at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-06-03 22:50 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-06-03 22:50 -------
Invalid as you see from the XLC output that bitfields alignment is not defined on char.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


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


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

end of thread, other threads:[~2004-06-03 22:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-03-30 19:13 [Bug c/14786] New: Struct misaligned containing unsigned char bit-field ryanma at cpsc dot ucalgary dot ca
2004-03-30 19:36 ` [Bug c/14786] " pinskia at gcc dot gnu dot org
2004-03-31 15:35 ` ryanma at cpsc dot ucalgary dot ca
2004-04-04  6:38 ` [Bug target/14786] " pinskia at gcc dot gnu dot org
2004-06-03 22:50 ` pinskia at gcc dot gnu dot org

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