From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8830 invoked by alias); 27 Jan 2012 18:05:40 -0000 Received: (qmail 8819 invoked by uid 22791); 27 Jan 2012 18:05:39 -0000 X-SWARE-Spam-Status: No, hits=-2.9 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 27 Jan 2012 18:05:26 +0000 From: "eggert at gnu dot org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/52023] New: _Alignof (double) yields wrong value on x86 Date: Fri, 27 Jan 2012 20:06:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Keywords: X-Bugzilla-Severity: major X-Bugzilla-Who: eggert at gnu dot org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2012-01/txt/msg03187.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52023 Bug #: 52023 Summary: _Alignof (double) yields wrong value on x86 Classification: Unclassified Product: gcc Version: 4.7.0 Status: UNCONFIRMED Severity: major Priority: P3 Component: c AssignedTo: unassigned@gcc.gnu.org ReportedBy: eggert@gnu.org Host: x86-64 Target: x86 Build: x86-64 Created attachment 26482 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=26482 gcc -v output On x86, alignof (double) should be 4, since that's the alignment requirement used for 'double' when laying out structures. But with GCC alignof incorrectly returns 8. This causes some gnulib tests to fail and (more importantly) it may cause problems with programs such as conservative garbage collectors that use alignof to determine which addresses might be of valid objects. The problem also occurs with other fundamental types, such as 'long long'. Here's a simple test case: #include #include int a = alignof (double); int b = offsetof (struct { char c; double d; }, d); int main (void) { return a == b; } Here's the preprocessed output: int a = _Alignof (double); int b = __builtin_offsetof (struct { char c; double d; }, d); int main (void) { return a == b; } 'main' should return 1, but it returns 0 due to the bug, which causes 'a' to be 8 instead of 4 as it should be. I'm using GCC on the trunk (r183603), built on Fedora 16 x86-64 with no special flags, and I'm compiling with 'gcc -v -m32 test.c' and running with './a.out'. I'm attaching the output of 'gcc -v'.