diff mbox

[C] Allow ATOMIC_*_LOCK_FREE in #if directive (DR#458)

Message ID 20140814174747.GD28810@redhat.com
State New
Headers show

Commit Message

Marek Polacek Aug. 14, 2014, 5:47 p.m. UTC
The DR#458 is about the usage of ATOMIC_*_LOCK_FREE macros defined in
stdatomic.h in the #if directives.  Proposed Technical Corrigendum of
this DR is that these macros should expand to constant expressions
suitable for use in #if preprocessing directives.  This patch does
that by mapping these macros to __GCC_ATOMIC_*_LOCK_FREE variants
defined in c-cppbuiltin.c:cpp_atomic_builtins.  (It's what libsupc++
does.)  The current implementation wouldn't work in #if directives.

Bootstrapped/regtested on x86_64-linux, ok for trunk?

2014-08-14  Marek Polacek  <polacek@redhat.com>

	DR 458
	* ginclude/stdatomic.h (__atomic_type_lock_free): Remove.
	(ATOMIC_*_LOCK_FREE): Map to __GCC_ATOMIC_*_LOCK_FREE.

	* gcc.dg/c11-stdatomic-2.c: New test.


	Marek

Comments

Joseph Myers Aug. 14, 2014, 5:51 p.m. UTC | #1
On Thu, 14 Aug 2014, Marek Polacek wrote:

> The DR#458 is about the usage of ATOMIC_*_LOCK_FREE macros defined in
> stdatomic.h in the #if directives.  Proposed Technical Corrigendum of
> this DR is that these macros should expand to constant expressions
> suitable for use in #if preprocessing directives.  This patch does
> that by mapping these macros to __GCC_ATOMIC_*_LOCK_FREE variants
> defined in c-cppbuiltin.c:cpp_atomic_builtins.  (It's what libsupc++
> does.)  The current implementation wouldn't work in #if directives.
> 
> Bootstrapped/regtested on x86_64-linux, ok for trunk?

OK.
diff mbox

Patch

diff --git gcc/ginclude/stdatomic.h gcc/ginclude/stdatomic.h
index 108259b4..26b4b6e 100644
--- gcc/ginclude/stdatomic.h
+++ gcc/ginclude/stdatomic.h
@@ -95,30 +95,16 @@  typedef _Atomic __UINTMAX_TYPE__ atomic_uintmax_t;
 #define atomic_signal_fence(MO)	__atomic_signal_fence  (MO)
 #define atomic_is_lock_free(OBJ) __atomic_is_lock_free (sizeof (*(OBJ)), (OBJ))
 
-#define __atomic_type_lock_free(T)				\
-  (__atomic_always_lock_free (sizeof (T), (void *) 0)		\
-   ? 2								\
-   : (__atomic_is_lock_free (sizeof (T), (void *) 0) ? 1 : 0))
-#define ATOMIC_BOOL_LOCK_FREE			\
-  __atomic_type_lock_free (atomic_bool)
-#define ATOMIC_CHAR_LOCK_FREE			\
-  __atomic_type_lock_free (atomic_char)
-#define ATOMIC_CHAR16_T_LOCK_FREE		\
-  __atomic_type_lock_free (atomic_char16_t)
-#define ATOMIC_CHAR32_T_LOCK_FREE		\
-  __atomic_type_lock_free (atomic_char32_t)
-#define ATOMIC_WCHAR_T_LOCK_FREE		\
-  __atomic_type_lock_free (atomic_wchar_t)
-#define ATOMIC_SHORT_LOCK_FREE 			\
-  __atomic_type_lock_free (atomic_short)
-#define ATOMIC_INT_LOCK_FREE 			\
-  __atomic_type_lock_free (atomic_int)
-#define ATOMIC_LONG_LOCK_FREE			\
-  __atomic_type_lock_free (atomic_long)
-#define ATOMIC_LLONG_LOCK_FREE			\
-  __atomic_type_lock_free (atomic_llong)
-#define ATOMIC_POINTER_LOCK_FREE		\
-  __atomic_type_lock_free (void * _Atomic)
+#define ATOMIC_BOOL_LOCK_FREE		__GCC_ATOMIC_BOOL_LOCK_FREE
+#define ATOMIC_CHAR_LOCK_FREE		__GCC_ATOMIC_CHAR_LOCK_FREE
+#define ATOMIC_CHAR16_T_LOCK_FREE	__GCC_ATOMIC_CHAR16_T_LOCK_FREE
+#define ATOMIC_CHAR32_T_LOCK_FREE	__GCC_ATOMIC_CHAR32_T_LOCK_FREE
+#define ATOMIC_WCHAR_T_LOCK_FREE	__GCC_ATOMIC_WCHAR_T_LOCK_FREE
+#define ATOMIC_SHORT_LOCK_FREE		__GCC_ATOMIC_SHORT_LOCK_FREE
+#define ATOMIC_INT_LOCK_FREE		__GCC_ATOMIC_INT_LOCK_FREE
+#define ATOMIC_LONG_LOCK_FREE		__GCC_ATOMIC_LONG_LOCK_FREE
+#define ATOMIC_LLONG_LOCK_FREE		__GCC_ATOMIC_LLONG_LOCK_FREE
+#define ATOMIC_POINTER_LOCK_FREE	__GCC_ATOMIC_POINTER_LOCK_FREE
 
 
 /* Note that these macros require __typeof__ and __auto_type to remove
diff --git gcc/testsuite/gcc.dg/c11-stdatomic-2.c gcc/testsuite/gcc.dg/c11-stdatomic-2.c
index e69de29..d746b5c 100644
--- gcc/testsuite/gcc.dg/c11-stdatomic-2.c
+++ gcc/testsuite/gcc.dg/c11-stdatomic-2.c
@@ -0,0 +1,27 @@ 
+/* Test stdatomic.h header contents.  Test that ATOMIC_*_LOCK_FREE
+   macros can be used in an #if directive (DR#458).  */
+/* { dg-do preprocess } */
+/* { dg-options "-std=c11 -pedantic-errors" } */
+
+#include <stdatomic.h>
+
+#if ATOMIC_BOOL_LOCK_FREE
+#endif
+#if ATOMIC_CHAR_LOCK_FREE
+#endif
+#if ATOMIC_CHAR16_T_LOCK_FREE
+#endif
+#if ATOMIC_CHAR32_T_LOCK_FREE
+#endif
+#if ATOMIC_WCHAR_T_LOCK_FREE
+#endif
+#if ATOMIC_SHORT_LOCK_FREE
+#endif
+#if ATOMIC_INT_LOCK_FREE
+#endif
+#if ATOMIC_LONG_LOCK_FREE
+#endif
+#if ATOMIC_LLONG_LOCK_FREE
+#endif
+#if ATOMIC_POINTER_LOCK_FREE
+#endif