public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "ryanma at cpsc dot ucalgary dot ca" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/14786] New: Struct misaligned containing unsigned char bit-field
Date: Tue, 30 Mar 2004 19:13:00 -0000	[thread overview]
Message-ID: <20040330191303.14786.ryanma@cpsc.ucalgary.ca> (raw)

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


             reply	other threads:[~2004-03-30 19:13 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-03-30 19:13 ryanma at cpsc dot ucalgary dot ca [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20040330191303.14786.ryanma@cpsc.ucalgary.ca \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).