public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "alexey.lapshin at oracle dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/65147] New: alignment of std::atomic object is not correct Date: Fri, 20 Feb 2015 20:01:00 -0000 [thread overview] Message-ID: <bug-65147-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65147 Bug ID: 65147 Summary: alignment of std::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 According to the documentation - https://gcc.gnu.org/wiki/Atomic/GCCMM/UnalignedPolicy alignment of atomic object should match it`s size. Alignment in the test case below does not match with documentation. ~/atomic_test$ cat unaligned_atomic.cpp #include <atomic> #include <stdio.h> typedef struct { char c [8]; } power_of_two_obj; typedef struct { char c[1]; std::atomic<power_of_two_obj> ao; } container_struct; int main ( void ) { std::atomic<power_of_two_obj> obj1; container_struct obj2; printf("\n Size and Alignment of std::atomic object "); printf(" : sizeof(obj1) %d alignof(obj1) %d ", sizeof(obj1), alignof(obj1) ); printf("\n Size and Alignment of std::atomic member object "); printf(" : sizeof(obj2.ao) %d alignof(obj2.ao) %d \n", sizeof(obj2.ao), alignof(obj2.ao) ); return 0; } ~/atomic_test$ g++ -v Using built-in specs. COLLECT_GCC=g++ 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$ g++ -O -latomic -std=c++11 unaligned_atomic.cpp -m32 ~/atomic_test$ ./a.out Size and Alignment of std::atomic object : sizeof(obj1) 8 alignof(obj1) 1 Size and Alignment of std::atomic member object : sizeof(obj2.ao) 8 alignof(obj2.ao) 1 Alignment should be 8-bytes in above test case. This behavior also differs from gcc. Gcc aligns 8-bytes objects to 8-bytes. The bug was found on Solarix x86 -m32, but it could be on other platforms - SPARC, Linux, -m64. There is another problem with similar test case. If size of object is not power of two then size of corresponding atomic object is also not power of two. According to https://gcc.gnu.org/wiki/Atomic/GCCMM/UnalignedPolicy the size should be upsized in such case.
next reply other threads:[~2015-02-20 19:48 UTC|newest] Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top 2015-02-20 20:01 alexey.lapshin at oracle dot com [this message] 2015-02-20 22:11 ` [Bug c++/65147] " joseph at codesourcery dot com 2015-03-20 22:15 ` [Bug libstdc++/65147] " jason at gcc dot gnu.org 2015-03-23 18:07 ` alexey.lapshin at oracle dot com 2015-03-23 18:36 ` redi at gcc dot gnu.org 2015-03-26 19:59 ` redi at gcc dot gnu.org 2015-03-26 20:24 ` redi at gcc dot gnu.org 2015-03-27 15:58 ` alexey.lapshin at oracle dot com 2015-03-27 19:15 ` redi at gcc dot gnu.org 2015-03-28 10:29 ` redi at gcc dot gnu.org 2015-03-30 11:42 ` redi at gcc dot gnu.org 2015-04-09 11:16 ` redi at gcc dot gnu.org 2015-04-09 11:18 ` redi at gcc dot gnu.org 2015-04-10 14:46 ` alexey.lapshin at oracle dot com 2015-04-22 12:02 ` jakub at gcc dot gnu.org 2015-04-22 12:59 ` redi at gcc dot gnu.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=bug-65147-4@http.gcc.gnu.org/bugzilla/ \ --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: linkBe 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).