public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* c/3580: __attribute__((aligned(2))) on a char array typedef affects unrelated char arrays.
@ 2001-07-05 16:26 dennisl
  0 siblings, 0 replies; 2+ messages in thread
From: dennisl @ 2001-07-05 16:26 UTC (permalink / raw)
  To: gcc-gnats; +Cc: dennislo

>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);
}



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

* Re: c/3580: __attribute__((aligned(2))) on a char array typedef affects unrelated char arrays.
@ 2001-10-05 11:42 jsm28
  0 siblings, 0 replies; 2+ messages in thread
From: jsm28 @ 2001-10-05 11:42 UTC (permalink / raw)
  To: jsm28, dennisl, dennislo, gcc-bugs, gcc-prs, nobody

Synopsis: __attribute__((aligned(2))) on a char array typedef affects unrelated char arrays.

State-Changed-From-To: open->closed
State-Changed-By: jsm28
State-Changed-When: Fri Oct  5 11:41:46 2001
State-Changed-Why:
    Fixed in 3.0.

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view&pr=3580&database=gcc


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

end of thread, other threads:[~2001-10-05 11:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-07-05 16:26 c/3580: __attribute__((aligned(2))) on a char array typedef affects unrelated char arrays dennisl
2001-10-05 11:42 jsm28

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