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

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