This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

stdatomic.h and atomic_load_explicit()


Hello,

GCC provides its own version of stdatomic.h since GCC 4.9.  Here we have:

#define atomic_load_explicit(PTR, MO)					\
  __extension__								\
  ({									\
    __auto_type __atomic_load_ptr = (PTR);				\
    __typeof__ (*__atomic_load_ptr) __atomic_load_tmp;			\
    __atomic_load (__atomic_load_ptr, &__atomic_load_tmp, (MO));	\
    __atomic_load_tmp;							\
  })

According to

http://en.cppreference.com/w/c/atomic/atomic_load

(or in the standard "7.17.7.2 The atomic_load generic functions") we have

C atomic_load_explicit( volatile A* obj, memory_order order );

This test case

#include <stdatomic.h>

int ld(volatile atomic_int *i)
{
  return atomic_load_explicit(i, memory_order_relaxed);
}

yields on ARM

arm-rtems4.11-gcc -march=armv7-a -O2 test.c -S && cat test.s
        .arch armv7-a
        .fpu softvfp
        .eabi_attribute 20, 1
        .eabi_attribute 21, 1
        .eabi_attribute 23, 3
        .eabi_attribute 24, 1
        .eabi_attribute 25, 1
        .eabi_attribute 26, 1
        .eabi_attribute 30, 2
        .eabi_attribute 34, 1
        .eabi_attribute 18, 4
        .file   "test.c"
        .text
        .align  2
        .global ld
        .type   ld, %function
ld:
        @ args = 0, pretend = 0, frame = 8
        @ frame_needed = 0, uses_anonymous_args = 0
        @ link register save eliminated.
        ldr     r3, [r0]
        sub     sp, sp, #8
        str     r3, [sp, #4]
        ldr     r0, [sp, #4]
        add     sp, sp, #8
        @ sp needed
        bx      lr
        .size   ld, .-ld
        .ident  "GCC: (GNU) 4.9.1 20140515 (prerelease)

I think the inheritance of the volatile qualifier via __typeof__ (*__atomic_load_ptr) is an implementation flaw.

With the FreeBSD version of <stdatomic.h> I don't have this problem:

http://svnweb.freebsd.org/base/head/include/stdatomic.h?revision=234958&view=markup&pathrev=234958#l231

--
Sebastian Huber, embedded brains GmbH

Address : Dornierstr. 4, D-82178 Puchheim, Germany
Phone   : +49 89 189 47 41-16
Fax     : +49 89 189 47 41-09
E-Mail  : sebastian.huber@embedded-brains.de
PGP     : Public key available on request.

Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]