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/65146] New: alignment of _Atomic structure member is not correct
Date: Fri, 20 Feb 2015 19:58:00 -0000	[thread overview]
Message-ID: <bug-65146-4@http.gcc.gnu.org/bugzilla/> (raw)

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65146

            Bug ID: 65146
           Summary: alignment of _Atomic structure member 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

Alignment of single _Atomic object match with documentation :
https://gcc.gnu.org/wiki/Atomic/GCCMM/UnalignedPolicy . 
Alignment of _Atomic structure member does not match. 

~/atomic_test$ cat unaligned_atomic.c

#include <stdatomic.h>
#include <stdio.h>

typedef struct {
    char c [8];
} power_of_two_obj;

typedef struct {
   char c[1];
   _Atomic power_of_two_obj ao;
} container_struct; 

int main ( void ) {

    _Atomic power_of_two_obj obj1;
    container_struct         obj2; 


    printf("\n Size and Alignment of _Atomic  object "); 
    printf(" : sizeof(obj1) %d __alignof__(obj1) %d ", sizeof(obj1),
__alignof__(obj1) );

    printf("\n Size and Alignment of _Atomic member object "); 
    printf(" : sizeof(obj2.ao) %d __alignof__(obj2.ao) %d \n", sizeof(obj2.ao),
__alignof__(obj2.ao) );

    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 unaligned_atomic.c -m32

~/atomic_test$ ./a.out

 Size and Alignment of _Atomic  object  : sizeof(obj1) 8 __alignof__(obj1) 8 
 Size and Alignment of _Atomic member object  : sizeof(obj2.ao) 8
__alignof__(obj2.ao) 4 


According to the documentation
https://gcc.gnu.org/wiki/Atomic/GCCMM/UnalignedPolicy alignment of both "obj1"
and "obj2.ao" should be 8 bytes.
But in the above test case alignment of obj2.ao is 4 bytes.

The bug is found on Solaris x86 -m32


             reply	other threads:[~2015-02-20 19:29 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-20 19:58 alexey.lapshin at oracle dot com [this message]
2015-02-20 21:43 ` [Bug c/65146] " joseph at codesourcery dot com
2015-02-20 22:51 ` alexey.lapshin at oracle dot com
2015-02-20 23:32 ` joseph at codesourcery dot com
2020-08-26 14:59 ` [Bug target/65146] " jason at gcc dot gnu.org
2020-08-26 16:03 ` jakub at gcc dot gnu.org
2020-08-26 17:33 ` jakub at gcc dot gnu.org
2020-08-26 17:58 ` hjl.tools at gmail dot com
2020-08-27 16:45 ` cvs-commit at gcc dot gnu.org
2022-04-27 12:37 ` peter at cordes dot ca
2023-12-04 10:10 ` egallager 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-65146-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: link
Be 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).