This is the mail archive of the
libc-ports@sources.redhat.com
mailing list for the libc-ports project.
Re: [PATCH roland/arm-atomic-warn] Fiddle ARM atomic.h to avoid -Wvolatile-register-var warnings.
- From: Richard Henderson <rth at twiddle dot net>
- To: Roland McGrath <roland at hack dot frob dot com>
- Cc: libc-ports at sourceware dot org
- Date: Wed, 08 Aug 2012 15:02:12 -0700
- Subject: Re: [PATCH roland/arm-atomic-warn] Fiddle ARM atomic.h to avoid -Wvolatile-register-var warnings.
- References: <20120808204442.9B9F82C085@topped-with-meat.com>
On 08/08/2012 01:44 PM, Roland McGrath wrote:
> + We use the union trick rather than simply using __typeof (...) in the
> + declarations of A_OLDVAL et al because when NEWVAL or OLDVAL is of the
> + form *PTR and PTR has a 'volatile ... *' type, then __typeof (*PTR) has
> + a 'volatile ...' type and this triggers -Wvolatile-register-var to
> + complain about 'register volatile ... asm ("reg")'. */
> #elif defined __thumb2__
> /* Thumb-2 has ldrex/strex. However it does not have barrier instructions,
> so we still need to use the kernel helper. */
> #define __arch_compare_and_exchange_val_32_acq(mem, newval, oldval) \
> - ({ register __typeof (oldval) a_oldval asm ("r0"); \
> - register __typeof (oldval) a_newval asm ("r1") = (newval); \
> + ({ union { __typeof (oldval) a; uint32_t v; } oldval_arg = { .a = (oldval) };\
> + union { __typeof (newval) a; uint32_t v; } newval_arg = { .a = (newval) };\
> + register uint32_t a_oldval asm ("r0"); \
> + register uint32_t a_newval asm ("r1") = newval_arg.v; \
> register __typeof (mem) a_ptr asm ("r2") = (mem); \
> - register __typeof (oldval) a_tmp asm ("r3"); \
> - register __typeof (oldval) a_oldval2 asm ("r4") = (oldval); \
> + register uint32_t a_tmp asm ("r3"); \
> + register uint32_t a_oldval2 asm ("r4") = oldval_arg.v; \
> __asm__ __volatile__ \
> ("0:\tldr\t%[tmp],[%[ptr]]\n\t" \
Is it really worth working so hard to avoid the gcc builtins?
Yes, gcc before 4.7 doesn't have __atomic to avoid the extra
barriers, but at least 4.7 and later will.
May I ask what gcc version you're targeting, anyway?
r~