aaron.ballman created this revision.
aaron.ballman added reviewers: rsmith, ldionne, cjdb, erichkeane.
aaron.ballman requested review of this revision.
Herald added a project: clang.

C17 deprecated `ATOMIC_VAR_INIT` with the resolution of DR 485. C++ followed 
suit when adopting P0883R2 for C++20, but additionally chose to deprecate 
`ATOMIC_FLAG_INIT` at the same time despite the macro still being required in 
C. This patch marks both macros as deprecated when appropriate to do so.

It does so by using `#pragma clang deprecated` and this patch presumes we don't 
have to guard those uses of the pragma with compiler or compiler version checks.

I believe libc++ will need some changes to address the deprecation as it seems 
it is using these macros. I'm not a libc++ maintainer and so I've added a few 
libc++ folks to the review so they can weigh in on whether libc++ should change 
first or can react to the changes in this patch. If libc++ needs to change 
first and you'd like me to drive those changes, I'd appreciate knowing what 
changes the maintainers would like to see there (I believe that removing the 
ATOMIC_VAR_INIT and using direct initialization would be appropriate, but I 
have no idea if the maintainers agree).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D112221

Files:
  clang/lib/Headers/stdatomic.h
  clang/test/Headers/stdatomic-deprecations.c


Index: clang/test/Headers/stdatomic-deprecations.c
===================================================================
--- /dev/null
+++ clang/test/Headers/stdatomic-deprecations.c
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c11 %s -verify=okay
+// RUN: %clang_cc1 -fsyntax-only -std=c17 %s -verify
+// RUN: %clang_cc1 -fsyntax-only -std=c++11 -x c++ %s -verify=okay
+// RUN: %clang_cc1 -fsyntax-only -std=c++20 -x c++ %s -verify=cxx,expected
+
+// okay-no-diagnostics
+
+#include <stdatomic.h>
+
+void func(void) {
+  (void)ATOMIC_VAR_INIT(12); // expected-warning {{macro 'ATOMIC_VAR_INIT' has 
been marked as deprecated}}
+  #if defined(ATOMIC_FLAG_INIT) // cxx-warning {{macro 'ATOMIC_FLAG_INIT' has 
been marked as deprecated}}
+  #endif
+}
+
Index: clang/lib/Headers/stdatomic.h
===================================================================
--- clang/lib/Headers/stdatomic.h
+++ clang/lib/Headers/stdatomic.h
@@ -40,6 +40,10 @@
 /* 7.17.2 Initialization */
 
 #define ATOMIC_VAR_INIT(value) (value)
+#if __STDC_VERSION__ >= 201710L || __cplusplus >= 202002L
+/* ATOMIC_VAR_INIT was deprecated in C17 and C++20. */
+#pragma clang deprecated(ATOMIC_VAR_INIT)
+#endif
 #define atomic_init __c11_atomic_init
 
 /* 7.17.3 Order and consistency */
@@ -149,6 +153,10 @@
 typedef struct atomic_flag { atomic_bool _Value; } atomic_flag;
 
 #define ATOMIC_FLAG_INIT { 0 }
+#if __cplusplus >= 202002L
+/* ATOMIC_FLAG_INIT was deprecated in C++20 but is not deprecated in C. */
+#pragma clang deprecated(ATOMIC_FLAG_INIT)
+#endif
 
 /* These should be provided by the libc implementation. */
 #ifdef __cplusplus


Index: clang/test/Headers/stdatomic-deprecations.c
===================================================================
--- /dev/null
+++ clang/test/Headers/stdatomic-deprecations.c
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c11 %s -verify=okay
+// RUN: %clang_cc1 -fsyntax-only -std=c17 %s -verify
+// RUN: %clang_cc1 -fsyntax-only -std=c++11 -x c++ %s -verify=okay
+// RUN: %clang_cc1 -fsyntax-only -std=c++20 -x c++ %s -verify=cxx,expected
+
+// okay-no-diagnostics
+
+#include <stdatomic.h>
+
+void func(void) {
+  (void)ATOMIC_VAR_INIT(12); // expected-warning {{macro 'ATOMIC_VAR_INIT' has been marked as deprecated}}
+  #if defined(ATOMIC_FLAG_INIT) // cxx-warning {{macro 'ATOMIC_FLAG_INIT' has been marked as deprecated}}
+  #endif
+}
+
Index: clang/lib/Headers/stdatomic.h
===================================================================
--- clang/lib/Headers/stdatomic.h
+++ clang/lib/Headers/stdatomic.h
@@ -40,6 +40,10 @@
 /* 7.17.2 Initialization */
 
 #define ATOMIC_VAR_INIT(value) (value)
+#if __STDC_VERSION__ >= 201710L || __cplusplus >= 202002L
+/* ATOMIC_VAR_INIT was deprecated in C17 and C++20. */
+#pragma clang deprecated(ATOMIC_VAR_INIT)
+#endif
 #define atomic_init __c11_atomic_init
 
 /* 7.17.3 Order and consistency */
@@ -149,6 +153,10 @@
 typedef struct atomic_flag { atomic_bool _Value; } atomic_flag;
 
 #define ATOMIC_FLAG_INIT { 0 }
+#if __cplusplus >= 202002L
+/* ATOMIC_FLAG_INIT was deprecated in C++20 but is not deprecated in C. */
+#pragma clang deprecated(ATOMIC_FLAG_INIT)
+#endif
 
 /* These should be provided by the libc implementation. */
 #ifdef __cplusplus
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to