[clang] 898c673 - [C2x] Remove the ATOMIC_VAR_INIT macro from stdatomic.h

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 24 10:54:29 PST 2023


Author: Aaron Ballman
Date: 2023-02-24T13:52:41-05:00
New Revision: 898c673e0835a2df395dd2476ac8ee8972d6380b

URL: https://github.com/llvm/llvm-project/commit/898c673e0835a2df395dd2476ac8ee8972d6380b
DIFF: https://github.com/llvm/llvm-project/commit/898c673e0835a2df395dd2476ac8ee8972d6380b.diff

LOG: [C2x] Remove the ATOMIC_VAR_INIT macro from stdatomic.h

This implements WG14 N2886 (https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2886.htm)
which removed the macro entirely. (NB the macro was deprecated in C17.)
As the paper is not particularly clear on what alternative was picked,
here are my notes from the May 2022 meeting:

Does WG14 wish to adopt variant 1, change 3.2, 3.3, and 3.4 from N2886
into C23?
14/2/2 (consensus)
Does WG14 want to exchange Variant 1 with Variant 2 in N2886 in C23?
9/3/6 (consensus)

(There was no sentiment in the room for either Variant 3 or Variant 4
so those were not voted on.)

Does WG14 want to integrate change 3.5 in N2886 into C23?
8/1/9 (consensus)
Does WG14 want to integrate change 3.6 in N2886 into C23?
2/5/9 (no consensus)

Any code that is broken by the removal can remove the use of
ATOMIC_VAR_INIT and use regular initialization instead.

Differential Revision: https://reviews.llvm.org/D144196

Added: 
    clang/test/C/C2x/n2886.c

Modified: 
    clang/docs/ReleaseNotes.rst
    clang/lib/Headers/stdatomic.h
    clang/www/c_status.html

Removed: 
    


################################################################################
diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index d7413def4d060..0397ba0b305eb 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -94,6 +94,9 @@ C2x Feature Support
 - Implemented the ``unreachable`` macro in freestanding ``<stddef.h>`` for
   `WG14 N2826 <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2826.pdf>`_
 
+- Removed the ``ATOMIC_VAR_INIT`` macro in C2x and later standards modes, which
+  implements `WG14 N2886 <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2886.htm>`_
+
 Non-comprehensive list of changes in this release
 -------------------------------------------------
 - Clang now saves the address of ABI-indirect function parameters on the stack,

diff  --git a/clang/lib/Headers/stdatomic.h b/clang/lib/Headers/stdatomic.h
index 0f893beea6ca2..48b3ab98c640c 100644
--- a/clang/lib/Headers/stdatomic.h
+++ b/clang/lib/Headers/stdatomic.h
@@ -45,9 +45,16 @@ extern "C" {
 #define ATOMIC_POINTER_LOCK_FREE    __CLANG_ATOMIC_POINTER_LOCK_FREE
 
 /* 7.17.2 Initialization */
-
+/* FIXME: This is using the placeholder dates Clang produces for these macros
+   in C2x mode; switch to the correct values once they've been published. */
+#if (defined(__STDC_VERSION__) && __STDC_VERSION__ < 202000L) ||               \
+    defined(__cplusplus)
+/* ATOMIC_VAR_INIT was removed in C2x, but still remains in C++2b. */
 #define ATOMIC_VAR_INIT(value) (value)
-#if ((defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201710L) ||             \
+#endif
+
+#if ((defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201710L &&              \
+      __STDC_VERSION__ < 202000L) ||                                           \
      (defined(__cplusplus) && __cplusplus >= 202002L)) &&                      \
     !defined(_CLANG_DISABLE_CRT_DEPRECATION_WARNINGS)
 /* ATOMIC_VAR_INIT was deprecated in C17 and C++20. */

diff  --git a/clang/test/C/C2x/n2886.c b/clang/test/C/C2x/n2886.c
new file mode 100644
index 0000000000000..ce733abdf0956
--- /dev/null
+++ b/clang/test/C/C2x/n2886.c
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -verify=okay -std=c11 -ffreestanding %s
+// RUN: %clang_cc1 -verify -std=c17 -ffreestanding %s
+// RUN: %clang_cc1 -verify -std=c2x -ffreestanding %s
+
+/* WG14 N2886: yes
+ * Remove ATOMIC_VAR_INIT v2
+ */
+
+/* okay-no-diagnostics */
+#include <stdatomic.h>
+
+_Atomic int a = ATOMIC_VAR_INIT(0); /* #diag */
+#if __STDC_VERSION__ <= 201710L
+/* expected-warning@#diag {{macro 'ATOMIC_VAR_INIT' has been marked as deprecated}}
+   expected-note at stdatomic.h:* {{macro marked 'deprecated' here}}
+*/
+#else
+/* expected-error@#diag {{use of undeclared identifier 'ATOMIC_VAR_INIT'}} */
+#endif
+

diff  --git a/clang/www/c_status.html b/clang/www/c_status.html
index ee0f116bc2908..f8cd9f1fd2fcc 100644
--- a/clang/www/c_status.html
+++ b/clang/www/c_status.html
@@ -1131,7 +1131,7 @@ <h2 id="c2x">C2x implementation status</h2>
     <tr>
       <td>Remove ATOMIC_VAR_INIT v2</td>
       <td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2886.htm">N2886</a></td>
-      <td class="none" align="center">No</td>
+      <td class="unreleased" align="center">Clang 17</td>
     </tr>
     <tr>
       <td>Require exact-width integer type interfaces v2</td>


        


More information about the cfe-commits mailing list