public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/65145] New: size of atomic object is not correct
@ 2015-02-20 19:48 alexey.lapshin at oracle dot com
  2015-02-20 21:19 ` [Bug c/65145] " joseph at codesourcery dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: alexey.lapshin at oracle dot com @ 2015-02-20 19:48 UTC (permalink / raw)
  To: gcc-bugs

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 <stdatomic.h>
#include <stdio.h>

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


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

* [Bug c/65145] size of atomic object is not correct
  2015-02-20 19:48 [Bug c/65145] New: size of atomic object is not correct alexey.lapshin at oracle dot com
@ 2015-02-20 21:19 ` joseph at codesourcery dot com
  2015-02-20 22:13 ` alexey.lapshin at oracle dot com
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: joseph at codesourcery dot com @ 2015-02-20 21:19 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from joseph at codesourcery dot com <joseph at codesourcery dot com> ---
On Fri, 20 Feb 2015, alexey.lapshin at oracle dot com wrote:

> The size of atomic object does not match with documentation -
> https://gcc.gnu.org/wiki/Atomic/GCCMM/UnalignedPolicy specifically : 

That's not documentation.  It's an early description of intent that does 
not correspond to what was actually implemented (note the future tense in 
the words you quote, and the last edited date a year before I added 
_Atomic support to trunk based on Andrew's work).  In general, old wiki 
pages are left around as they may help understand archived development 
discussions.


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

* [Bug c/65145] size of atomic object is not correct
  2015-02-20 19:48 [Bug c/65145] New: size of atomic object is not correct alexey.lapshin at oracle dot com
  2015-02-20 21:19 ` [Bug c/65145] " joseph at codesourcery dot com
@ 2015-02-20 22:13 ` alexey.lapshin at oracle dot com
  2015-02-20 23:24 ` joseph at codesourcery dot com
  2015-02-20 23:34 ` jsm28 at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: alexey.lapshin at oracle dot com @ 2015-02-20 22:13 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Alexey Lapshin <alexey.lapshin at oracle dot com> ---
Hi Joseph,

    Could you help me with a link to the correct description of atomic ABI,
which in fact used by gcc/g++, please ?

Thank you, Alexey.


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

* [Bug c/65145] size of atomic object is not correct
  2015-02-20 19:48 [Bug c/65145] New: size of atomic object is not correct alexey.lapshin at oracle dot com
  2015-02-20 21:19 ` [Bug c/65145] " joseph at codesourcery dot com
  2015-02-20 22:13 ` alexey.lapshin at oracle dot com
@ 2015-02-20 23:24 ` joseph at codesourcery dot com
  2015-02-20 23:34 ` jsm28 at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: joseph at codesourcery dot com @ 2015-02-20 23:24 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from joseph at codesourcery dot com <joseph at codesourcery dot com> ---
On Fri, 20 Feb 2015, alexey.lapshin at oracle dot com wrote:

> Hi Joseph,
> 
>     Could you help me with a link to the correct description of atomic ABI,
> which in fact used by gcc/g++, please ?

I don't believe it's documented, but I think the general rule for C is: if 
a type's size is 1, 2, 4, 8, 16, its alignment is increased by _Atomic to 
that of the atomic integer type of that size, which is the same as that of 
the non-atomic integer type unless increased by 
TARGET_ATOMIC_ALIGN_FOR_MODE; the size is never increased by _Atomic, and 
alignment of types not of those sizes is unchanged.  If the code differs, 
likely the code should take precedence over that description.  (But of 
course if a type is under-aligned for the instructions used to operate on 
it, there's a bug, whether in the alignment or in the instruction choice.)


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

* [Bug c/65145] size of atomic object is not correct
  2015-02-20 19:48 [Bug c/65145] New: size of atomic object is not correct alexey.lapshin at oracle dot com
                   ` (2 preceding siblings ...)
  2015-02-20 23:24 ` joseph at codesourcery dot com
@ 2015-02-20 23:34 ` jsm28 at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: jsm28 at gcc dot gnu.org @ 2015-02-20 23:34 UTC (permalink / raw)
  To: gcc-bugs

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

Joseph S. Myers <jsm28 at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

--- Comment #4 from Joseph S. Myers <jsm28 at gcc dot gnu.org> ---
Not a bug; there is no intent to increase object size with _Atomic.


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

end of thread, other threads:[~2015-02-20 23:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-20 19:48 [Bug c/65145] New: size of atomic object is not correct alexey.lapshin at oracle dot com
2015-02-20 21:19 ` [Bug c/65145] " joseph at codesourcery dot com
2015-02-20 22:13 ` alexey.lapshin at oracle dot com
2015-02-20 23:24 ` joseph at codesourcery dot com
2015-02-20 23:34 ` jsm28 at gcc dot gnu.org

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