aaron.ballman updated this revision to Diff 394597.
aaron.ballman marked 2 inline comments as done.
aaron.ballman added a comment.
Updated based on review feedback from Arthur.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D112221/new/
https://reviews.llvm.org/D112221
Files:
clang/docs/ReleaseNotes.rst
clang/docs/UsersManual.rst
clang/lib/Headers/stdatomic.h
clang/test/Headers/stdatomic-deprecations.c
libcxx/src/barrier.cpp
libcxx/src/experimental/memory_resource.cpp
libcxx/src/ios.cpp
Index: libcxx/src/ios.cpp
===================================================================
--- libcxx/src/ios.cpp
+++ libcxx/src/ios.cpp
@@ -137,7 +137,7 @@
// xalloc
#if defined(_LIBCPP_HAS_C_ATOMIC_IMP) && !defined(_LIBCPP_HAS_NO_THREADS)
-atomic<int> ios_base::__xindex_ = ATOMIC_VAR_INIT(0);
+atomic<int> ios_base::__xindex_ = 0;
#else
int ios_base::__xindex_ = 0;
#endif
Index: libcxx/src/experimental/memory_resource.cpp
===================================================================
--- libcxx/src/experimental/memory_resource.cpp
+++ libcxx/src/experimental/memory_resource.cpp
@@ -98,7 +98,7 @@
{
#ifndef _LIBCPP_HAS_NO_ATOMIC_HEADER
_LIBCPP_SAFE_STATIC static atomic<memory_resource*> __res =
- ATOMIC_VAR_INIT(&res_init.resources.new_delete_res);
+ &res_init.resources.new_delete_res;
if (set) {
new_res = new_res ? new_res : new_delete_resource();
// TODO: Can a weaker ordering be used?
Index: libcxx/src/barrier.cpp
===================================================================
--- libcxx/src/barrier.cpp
+++ libcxx/src/barrier.cpp
@@ -22,7 +22,7 @@
struct alignas(64) /* naturally-align the heap state */ __state_t
{
struct {
- __atomic_base<__barrier_phase_t> __phase = ATOMIC_VAR_INIT(0);
+ __atomic_base<__barrier_phase_t> __phase = 0;
} __tickets[64];
};
Index: clang/test/Headers/stdatomic-deprecations.c
===================================================================
--- /dev/null
+++ clang/test/Headers/stdatomic-deprecations.c
@@ -0,0 +1,18 @@
+// 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
+// RUN: %clang_cc1 -fsyntax-only -std=c++20 -x c++ %s -verify=okay -D_CLANG_DISABLE_CRT_DEPRECATION_WARNINGS
+// RUN: %clang_cc1 -fsyntax-only -std=c17 %s -verify=okay -D_CLANG_DISABLE_CRT_DEPRECATION_WARNINGS
+//
+// okay-no-diagnostics
+
+#include <stdatomic.h>
+
+void func(void) {
+ _Atomic int i = ATOMIC_VAR_INIT(12); // expected-warning {{macro 'ATOMIC_VAR_INIT' has been marked as deprecated}} \
+ // [email protected]:* {{macro marked 'deprecated' here}}
+ #if defined(ATOMIC_FLAG_INIT) // cxx-warning {{macro 'ATOMIC_FLAG_INIT' has been marked as deprecated}} \
+ // [email protected]:* {{macro marked 'deprecated' here}}
+ #endif
+}
Index: clang/lib/Headers/stdatomic.h
===================================================================
--- clang/lib/Headers/stdatomic.h
+++ clang/lib/Headers/stdatomic.h
@@ -44,6 +44,11 @@
/* 7.17.2 Initialization */
#define ATOMIC_VAR_INIT(value) (value)
+#if (__STDC_VERSION__ >= 201710L || __cplusplus >= 202002L) && \
+ !defined(_CLANG_DISABLE_CRT_DEPRECATION_WARNINGS)
+/* 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 */
@@ -153,6 +158,10 @@
typedef struct atomic_flag { atomic_bool _Value; } atomic_flag;
#define ATOMIC_FLAG_INIT { 0 }
+#if __cplusplus >= 202002L && !defined(_CLANG_DISABLE_CRT_DEPRECATION_WARNINGS)
+/* 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/docs/UsersManual.rst
===================================================================
--- clang/docs/UsersManual.rst
+++ clang/docs/UsersManual.rst
@@ -1114,10 +1114,25 @@
directory is treated as including a system header if the including file
is treated as a system header.
+Controlling Deprecation Diagnostics in Clang-Provided C Runtime Headers
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+Clang is responsible for providing some of the C runtime headers that cannot be
+provided by a platform CRT, such as implementation limits or when compiling in
+freestanding mode. Define the ``_CLANG_DISABLE_CRT_DEPRECATION_WARNINGS`` macro
+prior to including such a C runtime header to disable the deprecation warnings
+without also disabling other deprecation warnings.
+
+.. code-block:: c
+
+ #include <stdint.h> // May include Clang CRT deprecation warnings
+ #define _CLANG_DISABLE_CRT_DEPRECATION_WARNINGS
+ #include <stdatomic.h> // Clang CRT deprecation warnings are disabled
+
.. _diagnostics_enable_everything:
Enabling All Diagnostics
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+^^^^^^^^^^^^^^^^^^^^^^^^
In addition to the traditional ``-W`` flags, one can enable **all** diagnostics
by passing :option:`-Weverything`. This works as expected with
Index: clang/docs/ReleaseNotes.rst
===================================================================
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -156,6 +156,13 @@
stabilized, so this type should not yet be used in interfaces that require
ABI stability.
+ - The ``ATOMIC_VAR_INIT`` macro from ``<stdatomic.h>`` is now diagnosed as
+ deprecated in both C (C17 and later) and C++ (C++20 and later), and
+ ``ATOMIC_FLAG_INIT`` is now diagnosed as deprecated in C++ (C++20 and later).
+ The diagnostic can be disabled by defining the
+ ``_CLANG_DISABLE_CRT_DEPRECATION_WARNINGS`` macro prior to including the
+ header.
+
C++ Language Changes in Clang
-----------------------------
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits