From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7431 invoked by alias); 20 Feb 2015 19:09:09 -0000 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 Received: (qmail 7136 invoked by uid 48); 20 Feb 2015 19:09:05 -0000 From: "alexey.lapshin at oracle dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/65145] New: size of atomic object is not correct Date: Fri, 20 Feb 2015 19:48: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-Version: 4.9.2 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: alexey.lapshin at oracle dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2015-02/txt/msg02325.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65145 Bug ID: 65145 Summary: size of atomic object is not correct Product: gcc Version: 4.9.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: alexey.lapshin at oracle dot com The size of atomic object does not match with documentation - https://gcc.gnu.org/wiki/Atomic/GCCMM/UnalignedPolicy specifically : "GCC 4.9 will provide an atomic type attribute which can be set on objects. This attribute will force a specific alignment and size on the object which may be different than the original data type. The alignment and size will attempt to provide lock free operations, if they exist. ... An object will be promoted up to the next lock-free size in order to enable lock free operations, as long as it isn't already a documented lock free size. " ~/atomic_test$ cat non_power_2_atomic.c #include #include typedef struct { char c [5]; } non_power_to_obj; int main ( void ) { non_power_to_obj obj; _Atomic non_power_to_obj aobj; printf("\n Size and Alignment usual object "); printf(" : sizeof(obj) %d __alignof__(obj) %d ", sizeof(obj), __alignof__(obj) ); printf("\n Size and Alignment of atomic object "); printf(" : sizeof(aobj) %d __alignof__(aobj) %d \n", sizeof(aobj), __alignof__(aobj) ); return 0; } ~/atomic_test$ gcc -v Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/opt/gcc/libexec/gcc/i386-pc-solaris2.11/4.9.2/lto-wrapper Target: i386-pc-solaris2.11 Configured with: ./configure --prefix=/opt/gcc/ Thread model: posix gcc version 4.9.2 (GCC) ~/atomic_test$ gcc -O -latomic -std=c11 non_power_2_atomic.c ~/atomic_test$ ./a.out Size and Alignment usual object : sizeof(obj) 5 __alignof__(obj) 1 Size and Alignment of atomic object : sizeof(aobj) 5 __alignof__(aobj) 1 According to the https://gcc.gnu.org/wiki/Atomic/GCCMM/UnalignedPolicy the size and alignment of "aobj" should be 8. The bug us found on Solaris x86, but it could be on other platforms also(SPARC/Linux). This bug is also exist in g++.