From mboxrd@z Thu Jan 1 00:00:00 1970 From: dennisl@tri-linktech.com To: gcc-gnats@gcc.gnu.org Cc: dennislo@geocities.com Subject: c/3580: __attribute__((aligned(2))) on a char array typedef affects unrelated char arrays. Date: Thu, 05 Jul 2001 16:26:00 -0000 Message-id: <20010705232212.27505.qmail@sourceware.cygnus.com> X-SW-Source: 2001-07/msg00138.html List-Id: >Number: 3580 >Category: c >Synopsis: __attribute__((aligned(2))) on a char array typedef affects unrelated char arrays. >Confidential: no >Severity: serious >Priority: medium >Responsible: unassigned >State: open >Class: sw-bug >Submitter-Id: net >Arrival-Date: Thu Jul 05 16:26:00 PDT 2001 >Closed-Date: >Last-Modified: >Originator: Dennis Lo >Release: gcc version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release) >Organization: >Environment: Linux dlx.tri-linktech.com 2.2.14-5.0 #1 Tue Mar 7 20:53:41 EST 2000 i686 unknown >Description: Using __attribute__((aligned(2))) on a char array typedef will unintentionally apply this alignment on subsequently defined char arrays of the exactly the same size. In the following code, the char array typedef DUMMY is never used. When typedef DUMMY is commented out, this program prints "offset=1". When typedef DUMMY is uncommented, this program prints "offset=2". >How-To-Repeat: Compile the following code under RedHat 6.1 using "gcc bug.c" and then run a.out. It prints "offset=1". Uncomment the DUMMY typedef, recompile, and rerun. It prints "offset=2". >Fix: >Release-Note: >Audit-Trail: >Unformatted: ----gnatsweb-attachment---- Content-Type: text/plain; name="bug.c" Content-Disposition: inline; filename="bug.c" // // Synopsis: // __attribute__((aligned(2))) on a char array typedef affects // unrelated char arrays. // // Description: // Using __attribute__((aligned(2))) on a char array typedef will // unintentionally apply this alignment on subsequently defined char // arrays of the exactly the same size. // // In the following code, the char array typedef DUMMY is never used. // When typedef DUMMY is commented out, this program prints "offset=1". // When typedef DUMMY is uncommented, this program prints "offset=2". // // Release: // gcc version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release) // RedHat Linux 6.1. // // How to Repeat: // Compile the following code and run it. It prints "offset=1". // Uncomment the DUMMY typedef, compile, and run again. It prints // "offset=2". // //typedef char DUMMY[3] __attribute__((aligned(2))); typedef struct { char a1; char a2 [3]; } A; A aaa; int main (int argc, char* argv[]) { unsigned long offset = ((unsigned long) aaa.a2) - ((unsigned long) &aaa); printf ("offset=%lu\n", offset); }