[libcxx] [llvm] [libc++] Deprecate and remove meaningless `<cxxx>` headers (PR #111615)

A. Jiang via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 10 02:24:14 PDT 2024


https://github.com/frederick-vs-ja updated https://github.com/llvm/llvm-project/pull/111615

>From cd7e179a34a3696cc8b6f0c1db940b842a9ce3d1 Mon Sep 17 00:00:00 2001
From: "A. Jiang" <de34 at live.cn>
Date: Wed, 9 Oct 2024 09:52:29 +0800
Subject: [PATCH 01/10] [libc++] Deprecate and remove meaningless `<cxxx>`
 headers

`<ccomplex>`, `<cstdbool>`, `<ctgmath>`, and `<ciso646>` are deprecated
and "removed" by special deprecation warnings. `<cstdalign>` is
currently missing.
---
 libcxx/docs/ReleaseNotes/20.rst               |  7 ++++++-
 libcxx/docs/Status/Cxx17Papers.csv            |  2 +-
 libcxx/docs/Status/Cxx20Papers.csv            |  2 +-
 libcxx/include/ccomplex                       | 13 ++++++++++++
 libcxx/include/ciso646                        |  5 +++++
 libcxx/include/cstdbool                       | 13 ++++++++++++
 libcxx/include/ctgmath                        | 13 ++++++++++++
 .../depr.c.headers/ciso646.compile.pass.cpp   |  4 +++-
 .../depr/depr.cpp.headers/ccomplex.verify.cpp | 21 +++++++++++++++++++
 .../depr/depr.cpp.headers/ciso646.verify.cpp  | 17 +++++++++++++++
 .../depr/depr.cpp.headers/cstdbool.verify.cpp | 21 +++++++++++++++++++
 .../depr/depr.cpp.headers/ctgmath.verify.cpp  | 21 +++++++++++++++++++
 .../support.runtime/cstdbool.pass.cpp         |  4 +++-
 .../test/std/numerics/c.math/ctgmath.pass.cpp |  4 +++-
 .../complex.number/ccmplx/ccomplex.pass.cpp   |  4 +++-
 15 files changed, 144 insertions(+), 7 deletions(-)
 create mode 100644 libcxx/test/std/depr/depr.cpp.headers/ccomplex.verify.cpp
 create mode 100644 libcxx/test/std/depr/depr.cpp.headers/ciso646.verify.cpp
 create mode 100644 libcxx/test/std/depr/depr.cpp.headers/cstdbool.verify.cpp
 create mode 100644 libcxx/test/std/depr/depr.cpp.headers/ctgmath.verify.cpp

diff --git a/libcxx/docs/ReleaseNotes/20.rst b/libcxx/docs/ReleaseNotes/20.rst
index 82c8286b69e23c..22f98bb1a2089a 100644
--- a/libcxx/docs/ReleaseNotes/20.rst
+++ b/libcxx/docs/ReleaseNotes/20.rst
@@ -38,8 +38,9 @@ What's New in Libc++ 20.0.0?
 Implemented Papers
 ------------------
 
-- P2747R2: ``constexpr`` placement new (`Github <https://github.com/llvm/llvm-project/issues/105427>`__)
+- P0619R4: Reviewing Deprecated Facilities of C++17 for C++20 (`Github <https://github.com/llvm/llvm-project/issues/99985>`__)
 - P2609R3: Relaxing Ranges Just A Smidge (`Github <https://github.com/llvm/llvm-project/issues/105253>`__)
+- P2747R2: ``constexpr`` placement new (`Github <https://github.com/llvm/llvm-project/issues/105427>`__)
 - P2985R0: A type trait for detecting virtual base classes (`Github <https://github.com/llvm/llvm-project/issues/105432>`__)
 - ``std::jthread`` and ``<stop_token>`` are not guarded behind ``-fexperimental-library`` anymore
 
@@ -77,6 +78,10 @@ Deprecations and Removals
   supported as an extension anymore, please migrate any code that uses e.g. ``std::vector<const T>`` to be
   standards conforming.
 
+- ``<ccomplex>``, ``<cstdbool>``, and ``<ctgmath>`` are deprecated since C++17 as specified by the standard. They,
+  together with ``<ciso646>``, are removed in C++20, but libc++ still provides these headers as an extension and only
+  deprecates them.
+
 Upcoming Deprecations and Removals
 ----------------------------------
 
diff --git a/libcxx/docs/Status/Cxx17Papers.csv b/libcxx/docs/Status/Cxx17Papers.csv
index 3b56807312d556..feb2c68f60cb46 100644
--- a/libcxx/docs/Status/Cxx17Papers.csv
+++ b/libcxx/docs/Status/Cxx17Papers.csv
@@ -43,7 +43,7 @@
 "","","","","",""
 "`P0032R3 <https://wg21.link/P0032R3>`__","Homogeneous interface for variant, any and optional","2016-06 (Oulu)","|Complete|","4.0",""
 "`P0040R3 <https://wg21.link/P0040R3>`__","Extending memory management tools","2016-06 (Oulu)","|Complete|","4.0",""
-"`P0063R3 <https://wg21.link/P0063R3>`__","C++17 should refer to C11 instead of C99","2016-06 (Oulu)","|Complete|","7.0",""
+"`P0063R3 <https://wg21.link/P0063R3>`__","C++17 should refer to C11 instead of C99","2016-06 (Oulu)","|Complete|","7.0","``<ccomplex>``, ``<cstdbool>``, and ``<ctgmath>`` are deprecated since LLVM 20."
 "`P0067R3 <https://wg21.link/P0067R3>`__","Elementary string conversions","2016-06 (Oulu)","|Nothing To Do|","n/a","Resolved by `P0067R5 <https://wg21.link/P0067R5>`__"
 "`P0083R3 <https://wg21.link/P0083R3>`__","Splicing Maps and Sets","2016-06 (Oulu)","|Complete|","8.0",""
 "`P0084R2 <https://wg21.link/P0084R2>`__","Emplace Return Type","2016-06 (Oulu)","|Complete|","4.0",""
diff --git a/libcxx/docs/Status/Cxx20Papers.csv b/libcxx/docs/Status/Cxx20Papers.csv
index cc75d28f14aac2..daa611ccd6fded 100644
--- a/libcxx/docs/Status/Cxx20Papers.csv
+++ b/libcxx/docs/Status/Cxx20Papers.csv
@@ -34,7 +34,7 @@
 "`P0528R3 <https://wg21.link/P0528R3>`__","The Curious Case of Padding Bits, Featuring Atomic Compare-and-Exchange","2018-06 (Rapperswil)","","",""
 "`P0542R5 <https://wg21.link/P0542R5>`__","Support for contract based programming in C++","2018-06 (Rapperswil)","|Nothing To Do|","n/a","Pulled at the 2019-07 meeting in Cologne"
 "`P0556R3 <https://wg21.link/P0556R3>`__","Integral power-of-2 operations","2018-06 (Rapperswil)","|Complete|","9.0",""
-"`P0619R4 <https://wg21.link/P0619R4>`__","Reviewing Deprecated Facilities of C++17 for C++20","2018-06 (Rapperswil)","|Partial|","","Only sections D.7, D.8, D.9, D.10, D.11, D.12, and D.13 are implemented. Section D.4 remains undone."
+"`P0619R4 <https://wg21.link/P0619R4>`__","Reviewing Deprecated Facilities of C++17 for C++20","2018-06 (Rapperswil)","|Complete|","20.0","Removed headers are still provided as an extension, but with deprecation warnings"
 "`P0646R1 <https://wg21.link/P0646R1>`__","Improving the Return Value of Erase-Like Algorithms","2018-06 (Rapperswil)","|Complete|","10.0",""
 "`P0722R3 <https://wg21.link/P0722R3>`__","Efficient sized delete for variable sized classes","2018-06 (Rapperswil)","|Complete|","9.0",""
 "`P0758R1 <https://wg21.link/P0758R1>`__","Implicit conversion traits and utility functions","2018-06 (Rapperswil)","|Complete|","",""
diff --git a/libcxx/include/ccomplex b/libcxx/include/ccomplex
index 94d2c8d7d003d4..e498e06cad20a0 100644
--- a/libcxx/include/ccomplex
+++ b/libcxx/include/ccomplex
@@ -23,4 +23,17 @@
 #  pragma GCC system_header
 #endif
 
+#if _LIBCPP_STD_VER >= 17
+#  if _LIBCPP_STD_VER >= 20
+#    define _DEPRECATION_ANNOTATION _LIBCPP_DEPRECATED_("removed in C++20")
+#  else
+#    define _DEPRECATION_ANNOTATION _LIBCPP_DEPRECATED
+#  endif
+
+using __standard_header_ccomplex _DEPRECATION_ANNOTATION = void;
+using __use_standard_header_ccomplex                     = __standard_header_ccomplex;
+
+#  undef _DEPRECATION_ANNOTATION
+#endif
+
 #endif // _LIBCPP_CCOMPLEX
diff --git a/libcxx/include/ciso646 b/libcxx/include/ciso646
index 1d859f08fac572..4fd409ae9c6666 100644
--- a/libcxx/include/ciso646
+++ b/libcxx/include/ciso646
@@ -21,4 +21,9 @@
 #  pragma GCC system_header
 #endif
 
+#if _LIBCPP_STD_VER >= 20
+using __standard_header_ciso646 _LIBCPP_DEPRECATED_("removed in C++20") = void;
+using __use_standard_header_ciso646                                     = __standard_header_ciso646;
+#endif
+
 #endif // _LIBCPP_CISO646
diff --git a/libcxx/include/cstdbool b/libcxx/include/cstdbool
index ef731c021a4ab8..decd9ee6e9cece 100644
--- a/libcxx/include/cstdbool
+++ b/libcxx/include/cstdbool
@@ -28,4 +28,17 @@ Macros:
 #undef __bool_true_false_are_defined
 #define __bool_true_false_are_defined 1
 
+#if _LIBCPP_STD_VER >= 17
+#  if _LIBCPP_STD_VER >= 20
+#    define _DEPRECATION_ANNOTATION _LIBCPP_DEPRECATED_("removed in C++20")
+#  else
+#    define _DEPRECATION_ANNOTATION _LIBCPP_DEPRECATED
+#  endif
+
+using __standard_header_cstdbool _DEPRECATION_ANNOTATION = void;
+using __use_standard_header_cstdbool                     = __standard_header_cstdbool;
+
+#  undef _DEPRECATION_ANNOTATION
+#endif
+
 #endif // _LIBCPP_CSTDBOOL
diff --git a/libcxx/include/ctgmath b/libcxx/include/ctgmath
index 6237979be4906c..370470576bd3d7 100644
--- a/libcxx/include/ctgmath
+++ b/libcxx/include/ctgmath
@@ -25,4 +25,17 @@
 #  pragma GCC system_header
 #endif
 
+#if _LIBCPP_STD_VER >= 17
+#  if _LIBCPP_STD_VER >= 20
+#    define _DEPRECATION_ANNOTATION _LIBCPP_DEPRECATED_("removed in C++20")
+#  else
+#    define _DEPRECATION_ANNOTATION _LIBCPP_DEPRECATED
+#  endif
+
+using __standard_header_ctgmath _DEPRECATION_ANNOTATION = void;
+using __use_standard_header_ctgmath                     = __standard_header_ctgmath;
+
+#  undef _DEPRECATION_ANNOTATION
+#endif
+
 #endif // _LIBCPP_CTGMATH
diff --git a/libcxx/test/std/depr/depr.c.headers/ciso646.compile.pass.cpp b/libcxx/test/std/depr/depr.c.headers/ciso646.compile.pass.cpp
index 4dff57f84f202c..764f4d02f44f44 100644
--- a/libcxx/test/std/depr/depr.c.headers/ciso646.compile.pass.cpp
+++ b/libcxx/test/std/depr/depr.c.headers/ciso646.compile.pass.cpp
@@ -6,6 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-// <ciso646>
+// <ciso646> // removed in C++20, but still provided by libc++ as an extension
+
+// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS
 
 #include <ciso646>
diff --git a/libcxx/test/std/depr/depr.cpp.headers/ccomplex.verify.cpp b/libcxx/test/std/depr/depr.cpp.headers/ccomplex.verify.cpp
new file mode 100644
index 00000000000000..e012b5fd5d28ba
--- /dev/null
+++ b/libcxx/test/std/depr/depr.cpp.headers/ccomplex.verify.cpp
@@ -0,0 +1,21 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// <ccomplex>
+
+// check that <ccomplex> is deprecated in C++17 and removed in C++20
+
+// UNSUPPORTED: c++03, c++11, c++14
+
+#include "test_macros.h"
+
+#if TEST_STD_VER >= 20
+#  include <ccomplex> // expected-warning {{'__standard_header_ccomplex' is deprecated: removed in C++20}}
+#else
+#  include <ccomplex> // expected-warning {{'__standard_header_ccomplex' is deprecated}}
+#endif
diff --git a/libcxx/test/std/depr/depr.cpp.headers/ciso646.verify.cpp b/libcxx/test/std/depr/depr.cpp.headers/ciso646.verify.cpp
new file mode 100644
index 00000000000000..2f84fd13b96698
--- /dev/null
+++ b/libcxx/test/std/depr/depr.cpp.headers/ciso646.verify.cpp
@@ -0,0 +1,17 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// <ciso646>
+
+// check that <ciso646> is removed in C++20
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17
+
+#include "test_macros.h"
+
+#include <ciso646> // expected-warning {{'__standard_header_ciso646' is deprecated: removed in C++20}}
diff --git a/libcxx/test/std/depr/depr.cpp.headers/cstdbool.verify.cpp b/libcxx/test/std/depr/depr.cpp.headers/cstdbool.verify.cpp
new file mode 100644
index 00000000000000..99073ce0c9d091
--- /dev/null
+++ b/libcxx/test/std/depr/depr.cpp.headers/cstdbool.verify.cpp
@@ -0,0 +1,21 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// <cstdbool>
+
+// check that <cstdbool> is deprecated in C++17 and removed in C++20
+
+// UNSUPPORTED: c++03, c++11, c++14
+
+#include "test_macros.h"
+
+#if TEST_STD_VER >= 20
+#  include <cstdbool> // expected-warning {{'__standard_header_cstdbool' is deprecated: removed in C++20}}
+#else
+#  include <cstdbool> // expected-warning {{'__standard_header_cstdbool' is deprecated}}
+#endif
diff --git a/libcxx/test/std/depr/depr.cpp.headers/ctgmath.verify.cpp b/libcxx/test/std/depr/depr.cpp.headers/ctgmath.verify.cpp
new file mode 100644
index 00000000000000..f2b77f2b0c7905
--- /dev/null
+++ b/libcxx/test/std/depr/depr.cpp.headers/ctgmath.verify.cpp
@@ -0,0 +1,21 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// <ctgmath>
+
+// check that <ctgmath> is deprecated in C++17 and removed in C++20
+
+// UNSUPPORTED: c++03, c++11, c++14
+
+#include "test_macros.h"
+
+#if TEST_STD_VER >= 20
+#  include <ctgmath> // expected-warning {{'__standard_header_ctgmath' is deprecated: removed in C++20}}
+#else
+#  include <ctgmath> // expected-warning {{'__standard_header_ctgmath' is deprecated}}
+#endif
diff --git a/libcxx/test/std/language.support/support.runtime/cstdbool.pass.cpp b/libcxx/test/std/language.support/support.runtime/cstdbool.pass.cpp
index 1d0e9b06a43d2e..9a35eea507c40a 100644
--- a/libcxx/test/std/language.support/support.runtime/cstdbool.pass.cpp
+++ b/libcxx/test/std/language.support/support.runtime/cstdbool.pass.cpp
@@ -6,7 +6,9 @@
 //
 //===----------------------------------------------------------------------===//
 
-// test <cstdbool>
+// test <cstdbool> // deprecated in C++17, removed in C++20, but still provided by libc++ as an extension
+
+// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS
 
 #include <cstdbool>
 
diff --git a/libcxx/test/std/numerics/c.math/ctgmath.pass.cpp b/libcxx/test/std/numerics/c.math/ctgmath.pass.cpp
index 2c8d054fbc527d..2e4679980577a9 100644
--- a/libcxx/test/std/numerics/c.math/ctgmath.pass.cpp
+++ b/libcxx/test/std/numerics/c.math/ctgmath.pass.cpp
@@ -6,7 +6,9 @@
 //
 //===----------------------------------------------------------------------===//
 
-// <ctgmath>
+// <ctgmath> // deprecated in C++17, removed in C++20, but still provided by libc++ as an extension
+
+// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS
 
 #include <ctgmath>
 
diff --git a/libcxx/test/std/numerics/complex.number/ccmplx/ccomplex.pass.cpp b/libcxx/test/std/numerics/complex.number/ccmplx/ccomplex.pass.cpp
index cc3f8cd6a9beb9..0ed116c6410639 100644
--- a/libcxx/test/std/numerics/complex.number/ccmplx/ccomplex.pass.cpp
+++ b/libcxx/test/std/numerics/complex.number/ccmplx/ccomplex.pass.cpp
@@ -6,7 +6,9 @@
 //
 //===----------------------------------------------------------------------===//
 
-// <ccomplex>
+// <ccomplex> // deprecated in C++17, removed in C++20, but still provided by libc++ as an extension
+
+// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS
 
 #include <ccomplex>
 

>From a7fdda0b0ff2c9012e14163f5f55dff8ba1dab86 Mon Sep 17 00:00:00 2001
From: "A. Jiang" <de34 at live.cn>
Date: Wed, 9 Oct 2024 09:52:54 +0800
Subject: [PATCH 02/10] [libc++] Add missed `<cstdalign>` and `<stdalign.h>`
 headers

---
 libcxx/include/CMakeLists.txt                 |  2 +
 libcxx/include/cstdalign                      | 35 ++++++++++++++++
 libcxx/include/module.modulemap               |  9 ++++
 libcxx/include/stdalign.h                     | 42 +++++++++++++++++++
 libcxx/test/libcxx/include_as_c.sh.cpp        |  1 +
 .../stdalign_h.compile.pass.cpp               | 27 ++++++++++++
 .../support.runtime/cstdalign.pass.cpp        | 29 +++++++++++++
 libcxx/utils/libcxx/header_information.py     |  2 +-
 .../gn/secondary/libcxx/include/BUILD.gn      |  2 +
 9 files changed, 148 insertions(+), 1 deletion(-)
 create mode 100644 libcxx/include/cstdalign
 create mode 100644 libcxx/include/stdalign.h
 create mode 100644 libcxx/test/std/depr/depr.c.headers/stdalign_h.compile.pass.cpp
 create mode 100644 libcxx/test/std/language.support/support.runtime/cstdalign.pass.cpp

diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 9bd1b41b8bfac4..118a5bd82fbe90 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -909,6 +909,7 @@ set(files
   coroutine
   csetjmp
   csignal
+  cstdalign
   cstdarg
   cstdbool
   cstddef
@@ -992,6 +993,7 @@ set(files
   span
   sstream
   stack
+  stdalign.h
   stdatomic.h
   stdbool.h
   stddef.h
diff --git a/libcxx/include/cstdalign b/libcxx/include/cstdalign
new file mode 100644
index 00000000000000..4ab973374130ce
--- /dev/null
+++ b/libcxx/include/cstdalign
@@ -0,0 +1,35 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_CSTDALIGN
+#define _LIBCPP_CSTDALIGN
+
+/*
+    cstdalign synopsis
+
+Macros:
+
+    __alignas_is_defined
+    __alignof_is_defined
+
+*/
+
+#include <__config>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+#undef __alignas_is_defined
+#define __alignas_is_defined 1
+
+#undef __alignof_is_defined
+#define __alignof_is_defined 1
+
+#endif // _LIBCPP_CSTDALIGN
diff --git a/libcxx/include/module.modulemap b/libcxx/include/module.modulemap
index dee9b0b88b7948..f472335160bd84 100644
--- a/libcxx/include/module.modulemap
+++ b/libcxx/include/module.modulemap
@@ -1103,6 +1103,11 @@ module std [system] {
     export *
   }
 
+  module cstdalign {
+    header "cstdalign"
+    export *
+  }
+
   module cstdarg {
     header "cstdarg"
     export *
@@ -2187,6 +2192,10 @@ module std_math_h [system] {
   header "math.h"
   export *
 }
+module std_stdalign_h [system] {
+  // <stdalign.h>'s __alignas_is_defined and __alignof_is_defined macros require textual inclusion.
+  textual header "stdalign.h"
+}
 module std_stdatomic_h [system] {
   header "stdatomic.h"
   export *
diff --git a/libcxx/include/stdalign.h b/libcxx/include/stdalign.h
new file mode 100644
index 00000000000000..eb03f665151bd7
--- /dev/null
+++ b/libcxx/include/stdalign.h
@@ -0,0 +1,42 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_STDALIGN_H
+#define _LIBCPP_STDALIGN_H
+
+/*
+    stdalign.h synopsis
+
+Macros:
+
+    __alignas_is_defined
+    __alignof_is_defined
+
+*/
+
+#include <__config>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+#if __has_include_next(<stdalign.h>)
+#  include_next <stdalign.h>
+#endif
+
+#ifdef __cplusplus
+#  undef alignas
+#  undef alignof
+#  undef __alignas_is_defined
+#  undef __alignof_is_defined
+#  define __alignas_is_defined 1
+#  define __alignof_is_defined 1
+#endif
+
+#endif // _LIBCPP_STDALIGN_H
diff --git a/libcxx/test/libcxx/include_as_c.sh.cpp b/libcxx/test/libcxx/include_as_c.sh.cpp
index c9f8dfd9a5a922..204b830462cf94 100644
--- a/libcxx/test/libcxx/include_as_c.sh.cpp
+++ b/libcxx/test/libcxx/include_as_c.sh.cpp
@@ -34,6 +34,7 @@
 #endif
 #include <math.h>
 #include <setjmp.h>
+#include <stdalign.h>
 #include <stdatomic.h>
 #include <stdbool.h>
 #include <stddef.h>
diff --git a/libcxx/test/std/depr/depr.c.headers/stdalign_h.compile.pass.cpp b/libcxx/test/std/depr/depr.c.headers/stdalign_h.compile.pass.cpp
new file mode 100644
index 00000000000000..0f1cf487d60f6d
--- /dev/null
+++ b/libcxx/test/std/depr/depr.c.headers/stdalign_h.compile.pass.cpp
@@ -0,0 +1,27 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// test <stdalign.h>
+
+#include <stdalign.h>
+
+#ifndef __alignas_is_defined
+#  error __alignas_is_defined not defined
+#endif
+
+#ifndef __alignof_is_defined
+#  error __alignof_is_defined not defined
+#endif
+
+#ifdef alignas
+#  error alignas should not be defined
+#endif
+
+#ifdef alignof
+#  error alignof should not be defined
+#endif
diff --git a/libcxx/test/std/language.support/support.runtime/cstdalign.pass.cpp b/libcxx/test/std/language.support/support.runtime/cstdalign.pass.cpp
new file mode 100644
index 00000000000000..6b64fa575de2a9
--- /dev/null
+++ b/libcxx/test/std/language.support/support.runtime/cstdalign.pass.cpp
@@ -0,0 +1,29 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// test <cstdalign>
+
+#include <cstdalign>
+
+#ifndef __alignas_is_defined
+#  error __alignas_is_defined not defined
+#endif
+
+#ifndef __alignof_is_defined
+#  error __alignof_is_defined not defined
+#endif
+
+#ifdef alignas
+#  error alignas should not be defined
+#endif
+
+#ifdef alignof
+#  error alignof should not be defined
+#endif
+
+int main(int, char**) { return 0; }
diff --git a/libcxx/utils/libcxx/header_information.py b/libcxx/utils/libcxx/header_information.py
index fd48b35a88b558..1431ef2bfdc5ca 100644
--- a/libcxx/utils/libcxx/header_information.py
+++ b/libcxx/utils/libcxx/header_information.py
@@ -202,7 +202,7 @@ def is_modulemap_header(header):
     for header in toplevel_headers
     if not header.endswith(".h") and is_public_header(header)
     # These headers have been removed in C++20 so are never part of a module.
-    and not header in ["ccomplex", "ciso646", "cstdbool", "ctgmath"]
+    and not header in ["ccomplex", "ciso646", "cstdalign", "cstdbool", "ctgmath"]
 ]
 
 # The C headers used in the std and std.compat modules.
diff --git a/llvm/utils/gn/secondary/libcxx/include/BUILD.gn b/llvm/utils/gn/secondary/libcxx/include/BUILD.gn
index d850a7f20952d9..12945c91fff9d0 100644
--- a/llvm/utils/gn/secondary/libcxx/include/BUILD.gn
+++ b/llvm/utils/gn/secondary/libcxx/include/BUILD.gn
@@ -981,6 +981,7 @@ if (current_toolchain == default_toolchain) {
       "coroutine",
       "csetjmp",
       "csignal",
+      "cstdalign",
       "cstdarg",
       "cstdbool",
       "cstddef",
@@ -1064,6 +1065,7 @@ if (current_toolchain == default_toolchain) {
       "span",
       "sstream",
       "stack",
+      "stdalign.h",
       "stdatomic.h",
       "stdbool.h",
       "stddef.h",

>From fdf253d82e5bb05d06676606795a827b06ab8745 Mon Sep 17 00:00:00 2001
From: "A. Jiang" <de34 at live.cn>
Date: Wed, 9 Oct 2024 09:54:06 +0800
Subject: [PATCH 03/10] [libc++] Deprecate and remove `<cstdalign>`

---
 libcxx/docs/ReleaseNotes/20.rst               |  6 +++---
 libcxx/docs/Status/Cxx17Papers.csv            |  2 +-
 libcxx/include/cstdalign                      | 13 ++++++++++++
 .../depr.cpp.headers/cstdalign.verify.cpp     | 21 +++++++++++++++++++
 .../support.runtime/cstdalign.pass.cpp        |  4 +++-
 5 files changed, 41 insertions(+), 5 deletions(-)
 create mode 100644 libcxx/test/std/depr/depr.cpp.headers/cstdalign.verify.cpp

diff --git a/libcxx/docs/ReleaseNotes/20.rst b/libcxx/docs/ReleaseNotes/20.rst
index 22f98bb1a2089a..a65367d9b62c81 100644
--- a/libcxx/docs/ReleaseNotes/20.rst
+++ b/libcxx/docs/ReleaseNotes/20.rst
@@ -78,9 +78,9 @@ Deprecations and Removals
   supported as an extension anymore, please migrate any code that uses e.g. ``std::vector<const T>`` to be
   standards conforming.
 
-- ``<ccomplex>``, ``<cstdbool>``, and ``<ctgmath>`` are deprecated since C++17 as specified by the standard. They,
-  together with ``<ciso646>``, are removed in C++20, but libc++ still provides these headers as an extension and only
-  deprecates them.
+- ``<ccomplex>``, ``<cstdalign>`` (previously missing), ``<cstdbool>``, and ``<ctgmath>`` are deprecated since C++17 as
+  specified by the standard. They, together with ``<ciso646>``, are removed in C++20, but libc++ still provides these
+  headers as an extension and only deprecates them.
 
 Upcoming Deprecations and Removals
 ----------------------------------
diff --git a/libcxx/docs/Status/Cxx17Papers.csv b/libcxx/docs/Status/Cxx17Papers.csv
index feb2c68f60cb46..3058fd44c7250f 100644
--- a/libcxx/docs/Status/Cxx17Papers.csv
+++ b/libcxx/docs/Status/Cxx17Papers.csv
@@ -43,7 +43,7 @@
 "","","","","",""
 "`P0032R3 <https://wg21.link/P0032R3>`__","Homogeneous interface for variant, any and optional","2016-06 (Oulu)","|Complete|","4.0",""
 "`P0040R3 <https://wg21.link/P0040R3>`__","Extending memory management tools","2016-06 (Oulu)","|Complete|","4.0",""
-"`P0063R3 <https://wg21.link/P0063R3>`__","C++17 should refer to C11 instead of C99","2016-06 (Oulu)","|Complete|","7.0","``<ccomplex>``, ``<cstdbool>``, and ``<ctgmath>`` are deprecated since LLVM 20."
+"`P0063R3 <https://wg21.link/P0063R3>`__","C++17 should refer to C11 instead of C99","2016-06 (Oulu)","|Complete|","7.0","``<ccomplex>``, ``<cstdalign>``, ``<cstdbool>``, and ``<ctgmath>`` are deprecated since LLVM 20."
 "`P0067R3 <https://wg21.link/P0067R3>`__","Elementary string conversions","2016-06 (Oulu)","|Nothing To Do|","n/a","Resolved by `P0067R5 <https://wg21.link/P0067R5>`__"
 "`P0083R3 <https://wg21.link/P0083R3>`__","Splicing Maps and Sets","2016-06 (Oulu)","|Complete|","8.0",""
 "`P0084R2 <https://wg21.link/P0084R2>`__","Emplace Return Type","2016-06 (Oulu)","|Complete|","4.0",""
diff --git a/libcxx/include/cstdalign b/libcxx/include/cstdalign
index 4ab973374130ce..2d9187cdbfe8ac 100644
--- a/libcxx/include/cstdalign
+++ b/libcxx/include/cstdalign
@@ -32,4 +32,17 @@ Macros:
 #undef __alignof_is_defined
 #define __alignof_is_defined 1
 
+#if _LIBCPP_STD_VER >= 17
+#  if _LIBCPP_STD_VER >= 20
+#    define _DEPRECATION_ANNOTATION _LIBCPP_DEPRECATED_("removed in C++20")
+#  else
+#    define _DEPRECATION_ANNOTATION _LIBCPP_DEPRECATED
+#  endif
+
+using __standard_header_cstdalign _DEPRECATION_ANNOTATION = void;
+using __use_standard_header_cstdalign                     = __standard_header_cstdalign;
+
+#  undef _DEPRECATION_ANNOTATION
+#endif
+
 #endif // _LIBCPP_CSTDALIGN
diff --git a/libcxx/test/std/depr/depr.cpp.headers/cstdalign.verify.cpp b/libcxx/test/std/depr/depr.cpp.headers/cstdalign.verify.cpp
new file mode 100644
index 00000000000000..c73f183640a6e1
--- /dev/null
+++ b/libcxx/test/std/depr/depr.cpp.headers/cstdalign.verify.cpp
@@ -0,0 +1,21 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// <cstdalign>
+
+// check that <cstdalign> is deprecated in C++17 and removed in C++20
+
+// UNSUPPORTED: c++03, c++11, c++14
+
+#include "test_macros.h"
+
+#if TEST_STD_VER >= 20
+#  include <cstdalign> // expected-warning {{'__standard_header_cstdalign' is deprecated: removed in C++20}}
+#else
+#  include <cstdalign> // expected-warning {{'__standard_header_cstdalign' is deprecated}}
+#endif
diff --git a/libcxx/test/std/language.support/support.runtime/cstdalign.pass.cpp b/libcxx/test/std/language.support/support.runtime/cstdalign.pass.cpp
index 6b64fa575de2a9..186cd1e1c8bee8 100644
--- a/libcxx/test/std/language.support/support.runtime/cstdalign.pass.cpp
+++ b/libcxx/test/std/language.support/support.runtime/cstdalign.pass.cpp
@@ -6,7 +6,9 @@
 //
 //===----------------------------------------------------------------------===//
 
-// test <cstdalign>
+// test <cstdalign> // deprecated in C++17, removed in C++20, but still provided by libc++ as an extension
+
+// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS
 
 #include <cstdalign>
 

>From 81ea61bdfb3e0f0e83fee4d006646f9f67111faa Mon Sep 17 00:00:00 2001
From: "A. Jiang" <de34 at live.cn>
Date: Wed, 9 Oct 2024 11:10:12 +0800
Subject: [PATCH 04/10] Try to fix undeprecation/deprecation verification

---
 libcxx/test/libcxx/clang_modules_include.gen.py        |  3 ++-
 libcxx/test/libcxx/double_include.gen.py               |  3 ++-
 libcxx/test/libcxx/header_inclusions.gen.py            |  3 ++-
 libcxx/test/libcxx/libcpp_version.gen.py               |  3 ++-
 libcxx/test/libcxx/no_assert_include.gen.py            |  3 ++-
 libcxx/test/libcxx/system_reserved_names.gen.py        |  3 ++-
 .../test/std/depr/depr.cpp.headers/ccomplex.verify.cpp |  8 ++++++--
 .../test/std/depr/depr.cpp.headers/ciso646.verify.cpp  |  4 +++-
 .../std/depr/depr.cpp.headers/cstdalign.verify.cpp     |  8 ++++++--
 .../test/std/depr/depr.cpp.headers/cstdbool.verify.cpp |  8 ++++++--
 .../test/std/depr/depr.cpp.headers/ctgmath.verify.cpp  | 10 ++++++++--
 libcxx/utils/libcxx/header_information.py              |  8 ++++++++
 12 files changed, 49 insertions(+), 15 deletions(-)

diff --git a/libcxx/test/libcxx/clang_modules_include.gen.py b/libcxx/test/libcxx/clang_modules_include.gen.py
index bc028f2a0809aa..e72dafbe65ecb0 100644
--- a/libcxx/test/libcxx/clang_modules_include.gen.py
+++ b/libcxx/test/libcxx/clang_modules_include.gen.py
@@ -17,7 +17,7 @@
 
 import sys
 sys.path.append(sys.argv[1])
-from libcxx.header_information import lit_header_restrictions, public_headers
+from libcxx.header_information import lit_header_restrictions, lit_header_undeprecations, public_headers
 
 for header in public_headers:
   print(f"""\
@@ -41,6 +41,7 @@
 // UNSUPPORTED: LIBCXX-PICOLIBC-FIXME
 
 {lit_header_restrictions.get(header, '')}
+{lit_header_undeprecations.get(header, '')}
 
 #include <{header}>
 """)
diff --git a/libcxx/test/libcxx/double_include.gen.py b/libcxx/test/libcxx/double_include.gen.py
index afc2947dbece94..35f8c53f46ae57 100644
--- a/libcxx/test/libcxx/double_include.gen.py
+++ b/libcxx/test/libcxx/double_include.gen.py
@@ -15,12 +15,13 @@
 
 import sys
 sys.path.append(sys.argv[1])
-from libcxx.header_information import lit_header_restrictions, public_headers
+from libcxx.header_information import lit_header_restrictions, lit_header_undeprecations, public_headers
 
 for header in public_headers:
   print(f"""\
 //--- {header}.sh.cpp
 {lit_header_restrictions.get(header, '')}
+{lit_header_undeprecations.get(header, '')}
 
 // RUN: %{{cxx}} -c %s -o %t.first.o %{{flags}} %{{compile_flags}}
 // RUN: %{{cxx}} -c %s -o %t.second.o -DWITH_MAIN %{{flags}} %{{compile_flags}}
diff --git a/libcxx/test/libcxx/header_inclusions.gen.py b/libcxx/test/libcxx/header_inclusions.gen.py
index 2ecc47cbb1891a..97b2e0c9a90a56 100644
--- a/libcxx/test/libcxx/header_inclusions.gen.py
+++ b/libcxx/test/libcxx/header_inclusions.gen.py
@@ -13,7 +13,7 @@
 
 import sys
 sys.path.append(sys.argv[1])
-from libcxx.header_information import lit_header_restrictions, public_headers, mandatory_inclusions
+from libcxx.header_information import lit_header_restrictions, lit_header_undeprecations, public_headers, mandatory_inclusions
 
 for header in public_headers:
   header_guard = lambda h: f"_LIBCPP_{h.upper().replace('.', '_').replace('/', '_')}"
@@ -37,6 +37,7 @@
   print(f"""\
 //--- {header}.compile.pass.cpp
 {lit_header_restrictions.get(header, '')}
+{lit_header_undeprecations.get(header, '')}
 
 #include <{header}>
 {checks}
diff --git a/libcxx/test/libcxx/libcpp_version.gen.py b/libcxx/test/libcxx/libcpp_version.gen.py
index a9995295e21e4f..ddd88d6f4b9b07 100644
--- a/libcxx/test/libcxx/libcpp_version.gen.py
+++ b/libcxx/test/libcxx/libcpp_version.gen.py
@@ -12,12 +12,13 @@
 
 import sys
 sys.path.append(sys.argv[1])
-from libcxx.header_information import lit_header_restrictions, public_headers
+from libcxx.header_information import lit_header_restrictions, lit_header_undeprecations, public_headers
 
 for header in public_headers:
   print(f"""\
 //--- {header}.compile.pass.cpp
 {lit_header_restrictions.get(header, '')}
+{lit_header_undeprecations.get(header, '')}
 
 #include <{header}>
 
diff --git a/libcxx/test/libcxx/no_assert_include.gen.py b/libcxx/test/libcxx/no_assert_include.gen.py
index 67ab98603ca8fd..a8723744b734ab 100644
--- a/libcxx/test/libcxx/no_assert_include.gen.py
+++ b/libcxx/test/libcxx/no_assert_include.gen.py
@@ -13,7 +13,7 @@
 
 import sys
 sys.path.append(sys.argv[1])
-from libcxx.header_information import lit_header_restrictions, public_headers
+from libcxx.header_information import lit_header_restrictions, lit_header_undeprecations, public_headers
 
 for header in public_headers:
   if header == 'cassert':
@@ -22,6 +22,7 @@
   print(f"""\
 //--- {header}.compile.pass.cpp
 {lit_header_restrictions.get(header, '')}
+{lit_header_undeprecations.get(header, '')}
 
 #include <{header}>
 
diff --git a/libcxx/test/libcxx/system_reserved_names.gen.py b/libcxx/test/libcxx/system_reserved_names.gen.py
index e29e7a2cdd6144..35eeaa8c7e040c 100644
--- a/libcxx/test/libcxx/system_reserved_names.gen.py
+++ b/libcxx/test/libcxx/system_reserved_names.gen.py
@@ -14,13 +14,14 @@
 
 import sys
 sys.path.append(sys.argv[1])
-from libcxx.header_information import lit_header_restrictions, public_headers
+from libcxx.header_information import lit_header_restrictions, lit_header_undeprecations, public_headers
 
 for header in public_headers:
     print(
         f"""\
 //--- {header}.compile.pass.cpp
 {lit_header_restrictions.get(header, '')}
+{lit_header_undeprecations.get(header, '')}
 
 #define SYSTEM_RESERVED_NAME This name should not be used in libc++
 
diff --git a/libcxx/test/std/depr/depr.cpp.headers/ccomplex.verify.cpp b/libcxx/test/std/depr/depr.cpp.headers/ccomplex.verify.cpp
index e012b5fd5d28ba..34b7ad69f86460 100644
--- a/libcxx/test/std/depr/depr.cpp.headers/ccomplex.verify.cpp
+++ b/libcxx/test/std/depr/depr.cpp.headers/ccomplex.verify.cpp
@@ -15,7 +15,11 @@
 #include "test_macros.h"
 
 #if TEST_STD_VER >= 20
-#  include <ccomplex> // expected-warning {{'__standard_header_ccomplex' is deprecated: removed in C++20}}
+// expected-warning {{'__standard_header_ccomplex' is deprecated: removed in C++20}}
+
+#  include <ccomplex>
 #else
-#  include <ccomplex> // expected-warning {{'__standard_header_ccomplex' is deprecated}}
+// expected-warning {{'__standard_header_ccomplex' is deprecated}}
+
+#  include <ccomplex>
 #endif
diff --git a/libcxx/test/std/depr/depr.cpp.headers/ciso646.verify.cpp b/libcxx/test/std/depr/depr.cpp.headers/ciso646.verify.cpp
index 2f84fd13b96698..65ae794530bdc1 100644
--- a/libcxx/test/std/depr/depr.cpp.headers/ciso646.verify.cpp
+++ b/libcxx/test/std/depr/depr.cpp.headers/ciso646.verify.cpp
@@ -14,4 +14,6 @@
 
 #include "test_macros.h"
 
-#include <ciso646> // expected-warning {{'__standard_header_ciso646' is deprecated: removed in C++20}}
+// expected-warning {{'__standard_header_ciso646' is deprecated: removed in C++20}}
+
+#include <ciso646>
diff --git a/libcxx/test/std/depr/depr.cpp.headers/cstdalign.verify.cpp b/libcxx/test/std/depr/depr.cpp.headers/cstdalign.verify.cpp
index c73f183640a6e1..04d842ea5abf05 100644
--- a/libcxx/test/std/depr/depr.cpp.headers/cstdalign.verify.cpp
+++ b/libcxx/test/std/depr/depr.cpp.headers/cstdalign.verify.cpp
@@ -15,7 +15,11 @@
 #include "test_macros.h"
 
 #if TEST_STD_VER >= 20
-#  include <cstdalign> // expected-warning {{'__standard_header_cstdalign' is deprecated: removed in C++20}}
+// expected-warning {{'__standard_header_cstdalign' is deprecated: removed in C++20}}
+
+#  include <cstdalign>
 #else
-#  include <cstdalign> // expected-warning {{'__standard_header_cstdalign' is deprecated}}
+// expected-warning {{'__standard_header_cstdalign' is deprecated}}
+
+#  include <cstdalign>
 #endif
diff --git a/libcxx/test/std/depr/depr.cpp.headers/cstdbool.verify.cpp b/libcxx/test/std/depr/depr.cpp.headers/cstdbool.verify.cpp
index 99073ce0c9d091..304592009b71d6 100644
--- a/libcxx/test/std/depr/depr.cpp.headers/cstdbool.verify.cpp
+++ b/libcxx/test/std/depr/depr.cpp.headers/cstdbool.verify.cpp
@@ -15,7 +15,11 @@
 #include "test_macros.h"
 
 #if TEST_STD_VER >= 20
-#  include <cstdbool> // expected-warning {{'__standard_header_cstdbool' is deprecated: removed in C++20}}
+// expected-warning {{'__standard_header_cstdbool' is deprecated: removed in C++20}}
+
+#  include <cstdbool>
 #else
-#  include <cstdbool> // expected-warning {{'__standard_header_cstdbool' is deprecated}}
+// expected-warning {{'__standard_header_cstdbool' is deprecated}}
+
+#  include <cstdbool>
 #endif
diff --git a/libcxx/test/std/depr/depr.cpp.headers/ctgmath.verify.cpp b/libcxx/test/std/depr/depr.cpp.headers/ctgmath.verify.cpp
index f2b77f2b0c7905..7f47ffa683bf42 100644
--- a/libcxx/test/std/depr/depr.cpp.headers/ctgmath.verify.cpp
+++ b/libcxx/test/std/depr/depr.cpp.headers/ctgmath.verify.cpp
@@ -15,7 +15,13 @@
 #include "test_macros.h"
 
 #if TEST_STD_VER >= 20
-#  include <ctgmath> // expected-warning {{'__standard_header_ctgmath' is deprecated: removed in C++20}}
+// expected-warning {{'__standard_header_ccomplex' is deprecated: removed in C++20}}
+// expected-warning {{'__standard_header_ctgmath' is deprecated: removed in C++20}}
+
+#  include <ctgmath>
 #else
-#  include <ctgmath> // expected-warning {{'__standard_header_ctgmath' is deprecated}}
+// expected-warning {{'__standard_header_ccomplex' is deprecated}}
+// expected-warning {{'__standard_header_ctgmath' is deprecated}}
+
+#  include <ctgmath>
 #endif
diff --git a/libcxx/utils/libcxx/header_information.py b/libcxx/utils/libcxx/header_information.py
index 1431ef2bfdc5ca..1279b09bb32961 100644
--- a/libcxx/utils/libcxx/header_information.py
+++ b/libcxx/utils/libcxx/header_information.py
@@ -70,6 +70,14 @@
     "wchar.h": "// UNSUPPORTED: no-wide-characters",
     "wctype.h": "// UNSUPPORTED: no-wide-characters",
 }
+# Undeprecate headers that are deprecated in C++17 and removed in C++20.
+lit_header_undeprecations = {
+    "ccomplex": "// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS",
+    "ciso646": "// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS",
+    "cstdalign": "// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS",
+    "cstdbool": "// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS",
+    "ctgmath": "// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS",
+}
 
 # This table was produced manually, by grepping the TeX source of the Standard's
 # library clauses for the string "#include". Each header's synopsis contains

>From 887574ce5a49a452ca89804d90c8ad72cc2e365c Mon Sep 17 00:00:00 2001
From: "A. Jiang" <de34 at live.cn>
Date: Wed, 9 Oct 2024 11:52:58 +0800
Subject: [PATCH 05/10] Try to fix generating scripts

---
 .../test/libcxx/clang_modules_include.gen.py  | 14 +++++---
 libcxx/test/libcxx/double_include.gen.py      | 14 +++++---
 libcxx/test/libcxx/header_inclusions.gen.py   | 36 +++++++++++--------
 libcxx/test/libcxx/libcpp_version.gen.py      | 14 +++++---
 libcxx/test/libcxx/no_assert_include.gen.py   |  5 +--
 .../test/libcxx/system_reserved_names.gen.py  |  9 +++--
 libcxx/utils/libcxx/header_information.py     | 17 ++++-----
 7 files changed, 71 insertions(+), 38 deletions(-)

diff --git a/libcxx/test/libcxx/clang_modules_include.gen.py b/libcxx/test/libcxx/clang_modules_include.gen.py
index e72dafbe65ecb0..44afe603a19a3f 100644
--- a/libcxx/test/libcxx/clang_modules_include.gen.py
+++ b/libcxx/test/libcxx/clang_modules_include.gen.py
@@ -17,10 +17,15 @@
 
 import sys
 sys.path.append(sys.argv[1])
-from libcxx.header_information import lit_header_restrictions, lit_header_undeprecations, public_headers
+from libcxx.header_information import (
+    lit_header_restrictions,
+    header_undeprecations,
+    public_headers,
+)
 
 for header in public_headers:
-  print(f"""\
+    print(
+        f"""\
 //--- {header}.compile.pass.cpp
 // RUN: %{{cxx}} %s %{{flags}} %{{compile_flags}} -fmodules -fcxx-modules -fmodules-cache-path=%t -fsyntax-only
 
@@ -41,10 +46,11 @@
 // UNSUPPORTED: LIBCXX-PICOLIBC-FIXME
 
 {lit_header_restrictions.get(header, '')}
-{lit_header_undeprecations.get(header, '')}
+{header_undeprecations.get(header, '')}
 
 #include <{header}>
-""")
+"""
+    )
 
 print(
     f"""\
diff --git a/libcxx/test/libcxx/double_include.gen.py b/libcxx/test/libcxx/double_include.gen.py
index 35f8c53f46ae57..eabb04a5d1bed8 100644
--- a/libcxx/test/libcxx/double_include.gen.py
+++ b/libcxx/test/libcxx/double_include.gen.py
@@ -15,13 +15,18 @@
 
 import sys
 sys.path.append(sys.argv[1])
-from libcxx.header_information import lit_header_restrictions, lit_header_undeprecations, public_headers
+from libcxx.header_information import (
+    lit_header_restrictions,
+    header_undeprecations,
+    public_headers,
+)
 
 for header in public_headers:
-  print(f"""\
+    print(
+        f"""\
 //--- {header}.sh.cpp
 {lit_header_restrictions.get(header, '')}
-{lit_header_undeprecations.get(header, '')}
+{header_undeprecations.get(header, '')}
 
 // RUN: %{{cxx}} -c %s -o %t.first.o %{{flags}} %{{compile_flags}}
 // RUN: %{{cxx}} -c %s -o %t.second.o -DWITH_MAIN %{{flags}} %{{compile_flags}}
@@ -33,4 +38,5 @@
 #if defined(WITH_MAIN)
 int main(int, char**) {{ return 0; }}
 #endif
-""")
+"""
+    )
diff --git a/libcxx/test/libcxx/header_inclusions.gen.py b/libcxx/test/libcxx/header_inclusions.gen.py
index 97b2e0c9a90a56..d0c68654eb8135 100644
--- a/libcxx/test/libcxx/header_inclusions.gen.py
+++ b/libcxx/test/libcxx/header_inclusions.gen.py
@@ -12,33 +12,41 @@
 # RUN: %{python} %s %{libcxx-dir}/utils
 
 import sys
+
 sys.path.append(sys.argv[1])
-from libcxx.header_information import lit_header_restrictions, lit_header_undeprecations, public_headers, mandatory_inclusions
+from libcxx.header_information import (
+    lit_header_restrictions,
+    header_undeprecations,
+    public_headers,
+    mandatory_inclusions,
+)
 
 for header in public_headers:
-  header_guard = lambda h: f"_LIBCPP_{h.upper().replace('.', '_').replace('/', '_')}"
+    header_guard = lambda h: f"_LIBCPP_{h.upper().replace('.', '_').replace('/', '_')}"
 
-  # <cassert> has no header guards
-  if header == 'cassert':
-    checks = ''
-  else:
-    checks = f'''
+    # <cassert> has no header guards
+    if header == 'cassert':
+        checks = ""
+    else:
+        checks = f"""
 #ifndef {header_guard(header)}
 # error <{header}> was expected to define a header guard {header_guard(header)}
 #endif
-'''
-  for includee in mandatory_inclusions.get(header, []):
-    checks += f'''
+"""
+    for includee in mandatory_inclusions.get(header, []):
+        checks += f"""
 #ifndef {header_guard(includee)}
 # error <{header}> was expected to include <{includee}>
 #endif
-'''
+"""
 
-  print(f"""\
+    print(
+        f"""\
 //--- {header}.compile.pass.cpp
 {lit_header_restrictions.get(header, '')}
-{lit_header_undeprecations.get(header, '')}
+{header_undeprecations.get(header, '')}
 
 #include <{header}>
 {checks}
-""")
+"""
+    )
diff --git a/libcxx/test/libcxx/libcpp_version.gen.py b/libcxx/test/libcxx/libcpp_version.gen.py
index ddd88d6f4b9b07..fd9eca433b7667 100644
--- a/libcxx/test/libcxx/libcpp_version.gen.py
+++ b/libcxx/test/libcxx/libcpp_version.gen.py
@@ -12,17 +12,23 @@
 
 import sys
 sys.path.append(sys.argv[1])
-from libcxx.header_information import lit_header_restrictions, lit_header_undeprecations, public_headers
+from libcxx.header_information import (
+    lit_header_restrictions,
+    header_undeprecations,
+    public_headers,
+)
 
 for header in public_headers:
-  print(f"""\
+    print(
+        f"""\
 //--- {header}.compile.pass.cpp
 {lit_header_restrictions.get(header, '')}
-{lit_header_undeprecations.get(header, '')}
+{header_undeprecations.get(header, '')}
 
 #include <{header}>
 
 #ifndef _LIBCPP_VERSION
 # error <{header}> does not seem to define _LIBCPP_VERSION
 #endif
-""")
+"""
+    )
diff --git a/libcxx/test/libcxx/no_assert_include.gen.py b/libcxx/test/libcxx/no_assert_include.gen.py
index a8723744b734ab..fa7ed7b1e271c5 100644
--- a/libcxx/test/libcxx/no_assert_include.gen.py
+++ b/libcxx/test/libcxx/no_assert_include.gen.py
@@ -12,8 +12,9 @@
 # RUN: %{python} %s %{libcxx-dir}/utils
 
 import sys
+
 sys.path.append(sys.argv[1])
-from libcxx.header_information import lit_header_restrictions, lit_header_undeprecations, public_headers
+from libcxx.header_information import lit_header_restrictions, header_undeprecations, public_headers
 
 for header in public_headers:
   if header == 'cassert':
@@ -22,7 +23,7 @@
   print(f"""\
 //--- {header}.compile.pass.cpp
 {lit_header_restrictions.get(header, '')}
-{lit_header_undeprecations.get(header, '')}
+{header_undeprecations.get(header, '')}
 
 #include <{header}>
 
diff --git a/libcxx/test/libcxx/system_reserved_names.gen.py b/libcxx/test/libcxx/system_reserved_names.gen.py
index 35eeaa8c7e040c..6386781864fc73 100644
--- a/libcxx/test/libcxx/system_reserved_names.gen.py
+++ b/libcxx/test/libcxx/system_reserved_names.gen.py
@@ -13,15 +13,20 @@
 # RUN: %{python} %s %{libcxx-dir}/utils
 
 import sys
+
 sys.path.append(sys.argv[1])
-from libcxx.header_information import lit_header_restrictions, lit_header_undeprecations, public_headers
+from libcxx.header_information import (
+    lit_header_restrictions,
+    header_undeprecations,
+    public_headers,
+)
 
 for header in public_headers:
     print(
         f"""\
 //--- {header}.compile.pass.cpp
 {lit_header_restrictions.get(header, '')}
-{lit_header_undeprecations.get(header, '')}
+{header_undeprecations.get(header, '')}
 
 #define SYSTEM_RESERVED_NAME This name should not be used in libc++
 
diff --git a/libcxx/utils/libcxx/header_information.py b/libcxx/utils/libcxx/header_information.py
index 1279b09bb32961..a9da82f4597be2 100644
--- a/libcxx/utils/libcxx/header_information.py
+++ b/libcxx/utils/libcxx/header_information.py
@@ -32,6 +32,15 @@
     "syncstream": "!defined(_LIBCPP_HAS_NO_LOCALIZATION)",
 }
 
+# Undeprecate headers that are deprecated in C++17 and removed in C++20.
+header_undeprecations = {
+    "ccomplex": "#define _LIBCPP_DISABLE_DEPRECATION_WARNINGS",
+    "ciso646": "#define _LIBCPP_DISABLE_DEPRECATION_WARNINGS",
+    "cstdalign": "#define _LIBCPP_DISABLE_DEPRECATION_WARNINGS",
+    "cstdbool": "#define _LIBCPP_DISABLE_DEPRECATION_WARNINGS",
+    "ctgmath": "#define _LIBCPP_DISABLE_DEPRECATION_WARNINGS",
+}
+
 lit_header_restrictions = {
     "barrier": "// UNSUPPORTED: no-threads, c++03, c++11, c++14, c++17",
     "clocale": "// UNSUPPORTED: no-localization",
@@ -70,14 +79,6 @@
     "wchar.h": "// UNSUPPORTED: no-wide-characters",
     "wctype.h": "// UNSUPPORTED: no-wide-characters",
 }
-# Undeprecate headers that are deprecated in C++17 and removed in C++20.
-lit_header_undeprecations = {
-    "ccomplex": "// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS",
-    "ciso646": "// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS",
-    "cstdalign": "// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS",
-    "cstdbool": "// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS",
-    "ctgmath": "// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS",
-}
 
 # This table was produced manually, by grepping the TeX source of the Standard's
 # library clauses for the string "#include". Each header's synopsis contains

>From 18c7e9d0581c05efc35a1e4a8eb35050c0f3eb22 Mon Sep 17 00:00:00 2001
From: "A. Jiang" <de34 at live.cn>
Date: Wed, 9 Oct 2024 13:29:32 +0800
Subject: [PATCH 06/10] More formatting

---
 libcxx/test/libcxx/header_inclusions.gen.py |  2 +-
 libcxx/test/libcxx/no_assert_include.gen.py | 16 +++++++++++-----
 2 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/libcxx/test/libcxx/header_inclusions.gen.py b/libcxx/test/libcxx/header_inclusions.gen.py
index d0c68654eb8135..11d6e972f23e30 100644
--- a/libcxx/test/libcxx/header_inclusions.gen.py
+++ b/libcxx/test/libcxx/header_inclusions.gen.py
@@ -25,7 +25,7 @@
     header_guard = lambda h: f"_LIBCPP_{h.upper().replace('.', '_').replace('/', '_')}"
 
     # <cassert> has no header guards
-    if header == 'cassert':
+    if header == "cassert":
         checks = ""
     else:
         checks = f"""
diff --git a/libcxx/test/libcxx/no_assert_include.gen.py b/libcxx/test/libcxx/no_assert_include.gen.py
index fa7ed7b1e271c5..320949ef327392 100644
--- a/libcxx/test/libcxx/no_assert_include.gen.py
+++ b/libcxx/test/libcxx/no_assert_include.gen.py
@@ -14,13 +14,18 @@
 import sys
 
 sys.path.append(sys.argv[1])
-from libcxx.header_information import lit_header_restrictions, header_undeprecations, public_headers
+from libcxx.header_information import (
+    lit_header_restrictions,
+    header_undeprecations,
+    public_headers,
+)
 
 for header in public_headers:
-  if header == 'cassert':
-    continue
+    if header == "cassert":
+        continue
 
-  print(f"""\
+    print(
+        f"""\
 //--- {header}.compile.pass.cpp
 {lit_header_restrictions.get(header, '')}
 {header_undeprecations.get(header, '')}
@@ -30,4 +35,5 @@
 #ifdef assert
 # error "Do not include cassert or assert.h in standard header files"
 #endif
-""")
+"""
+    )

>From b68ee904676d1b2e30fd75fdc8a7ac48441e54d1 Mon Sep 17 00:00:00 2001
From: "A. Jiang" <de34 at live.cn>
Date: Wed, 9 Oct 2024 14:04:01 +0800
Subject: [PATCH 07/10] Reorganize inclusion per P0063R3 to reduce deprecation
 warnings

---
 libcxx/include/complex.h                                 | 6 +++++-
 libcxx/include/ctgmath                                   | 7 ++++++-
 libcxx/include/tgmath.h                                  | 7 ++++++-
 libcxx/test/std/depr/depr.cpp.headers/ctgmath.verify.cpp | 2 --
 4 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/libcxx/include/complex.h b/libcxx/include/complex.h
index a3da21c843f365..7e264abe963efe 100644
--- a/libcxx/include/complex.h
+++ b/libcxx/include/complex.h
@@ -24,7 +24,11 @@
 #endif
 
 #ifdef __cplusplus
-#  include <ccomplex>
+#  if _LIBCPP_STD_VER >= 17
+#    include <complex>
+#  else
+#    include <ccomplex>
+#  endif
 #elif __has_include_next(<complex.h>)
 #  include_next <complex.h>
 #endif
diff --git a/libcxx/include/ctgmath b/libcxx/include/ctgmath
index 370470576bd3d7..ebcd9c32b0e38a 100644
--- a/libcxx/include/ctgmath
+++ b/libcxx/include/ctgmath
@@ -18,7 +18,12 @@
 
 */
 
-#include <ccomplex>
+#if _LIBCPP_STD_VER >= 17
+#  include <complex>
+#else
+#  include <ccomplex>
+#endif
+
 #include <cmath>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
diff --git a/libcxx/include/tgmath.h b/libcxx/include/tgmath.h
index e6f0a4ab2611fa..9249b8467c8507 100644
--- a/libcxx/include/tgmath.h
+++ b/libcxx/include/tgmath.h
@@ -24,7 +24,12 @@
 #endif
 
 #ifdef __cplusplus
-#  include <ctgmath>
+#  if _LIBCPP_STD_VER >= 17
+#    include <complex>
+#    include <cmath>
+#  else
+#    include <ctgmath>
+#  endif
 #else
 #  if __has_include_next(<tgmath.h>)
 #    include_next <tgmath.h>
diff --git a/libcxx/test/std/depr/depr.cpp.headers/ctgmath.verify.cpp b/libcxx/test/std/depr/depr.cpp.headers/ctgmath.verify.cpp
index 7f47ffa683bf42..6c1f64489caaeb 100644
--- a/libcxx/test/std/depr/depr.cpp.headers/ctgmath.verify.cpp
+++ b/libcxx/test/std/depr/depr.cpp.headers/ctgmath.verify.cpp
@@ -15,12 +15,10 @@
 #include "test_macros.h"
 
 #if TEST_STD_VER >= 20
-// expected-warning {{'__standard_header_ccomplex' is deprecated: removed in C++20}}
 // expected-warning {{'__standard_header_ctgmath' is deprecated: removed in C++20}}
 
 #  include <ctgmath>
 #else
-// expected-warning {{'__standard_header_ccomplex' is deprecated}}
 // expected-warning {{'__standard_header_ctgmath' is deprecated}}
 
 #  include <ctgmath>

>From 70d91b749b7bea0e6348d3bfd7d4c5201b04fd1f Mon Sep 17 00:00:00 2001
From: "A. Jiang" <de34 at live.cn>
Date: Thu, 10 Oct 2024 17:22:32 +0800
Subject: [PATCH 08/10] Delete unneeded `<stdalign.h>`

---
 libcxx/include/stdalign.h | 42 ---------------------------------------
 1 file changed, 42 deletions(-)
 delete mode 100644 libcxx/include/stdalign.h

diff --git a/libcxx/include/stdalign.h b/libcxx/include/stdalign.h
deleted file mode 100644
index eb03f665151bd7..00000000000000
--- a/libcxx/include/stdalign.h
+++ /dev/null
@@ -1,42 +0,0 @@
-// -*- C++ -*-
-//===----------------------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef _LIBCPP_STDALIGN_H
-#define _LIBCPP_STDALIGN_H
-
-/*
-    stdalign.h synopsis
-
-Macros:
-
-    __alignas_is_defined
-    __alignof_is_defined
-
-*/
-
-#include <__config>
-
-#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
-#  pragma GCC system_header
-#endif
-
-#if __has_include_next(<stdalign.h>)
-#  include_next <stdalign.h>
-#endif
-
-#ifdef __cplusplus
-#  undef alignas
-#  undef alignof
-#  undef __alignas_is_defined
-#  undef __alignof_is_defined
-#  define __alignas_is_defined 1
-#  define __alignof_is_defined 1
-#endif
-
-#endif // _LIBCPP_STDALIGN_H

>From 8360774a7f5f716721b578067345c318b64d3034 Mon Sep 17 00:00:00 2001
From: "A. Jiang" <de34 at live.cn>
Date: Thu, 10 Oct 2024 17:23:08 +0800
Subject: [PATCH 09/10] Escape hatch for `<ciso646>`

---
 libcxx/docs/ReleaseNotes/20.rst | 3 ++-
 libcxx/include/ciso646          | 2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/libcxx/docs/ReleaseNotes/20.rst b/libcxx/docs/ReleaseNotes/20.rst
index a65367d9b62c81..c67a4526dc97ef 100644
--- a/libcxx/docs/ReleaseNotes/20.rst
+++ b/libcxx/docs/ReleaseNotes/20.rst
@@ -80,7 +80,8 @@ Deprecations and Removals
 
 - ``<ccomplex>``, ``<cstdalign>`` (previously missing), ``<cstdbool>``, and ``<ctgmath>`` are deprecated since C++17 as
   specified by the standard. They, together with ``<ciso646>``, are removed in C++20, but libc++ still provides these
-  headers as an extension and only deprecates them.
+  headers as an extension and only deprecates them. The ``_LIBCPP_ENABLE_REMOVED_CISO646`` macro can be defined to
+  suppress deprecation for ``<ciso646>``.
 
 Upcoming Deprecations and Removals
 ----------------------------------
diff --git a/libcxx/include/ciso646 b/libcxx/include/ciso646
index 4fd409ae9c6666..5298d41dc26667 100644
--- a/libcxx/include/ciso646
+++ b/libcxx/include/ciso646
@@ -21,7 +21,7 @@
 #  pragma GCC system_header
 #endif
 
-#if _LIBCPP_STD_VER >= 20
+#if _LIBCPP_STD_VER >= 20 && !defined(_LIBCPP_ENABLE_REMOVED_CISO646)
 using __standard_header_ciso646 _LIBCPP_DEPRECATED_("removed in C++20") = void;
 using __use_standard_header_ciso646                                     = __standard_header_ciso646;
 #endif

>From 9c4337c026cebb273d11491653703b5b8c2a85d1 Mon Sep 17 00:00:00 2001
From: "A. Jiang" <de34 at live.cn>
Date: Thu, 10 Oct 2024 17:23:38 +0800
Subject: [PATCH 10/10] Fix some errors for `<ctgmath>` and `<tgmath.h>`

---
 libcxx/include/ctgmath  | 2 ++
 libcxx/include/tgmath.h | 2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/libcxx/include/ctgmath b/libcxx/include/ctgmath
index ebcd9c32b0e38a..75e1326a424d4b 100644
--- a/libcxx/include/ctgmath
+++ b/libcxx/include/ctgmath
@@ -18,6 +18,8 @@
 
 */
 
+#include <__config>
+
 #if _LIBCPP_STD_VER >= 17
 #  include <complex>
 #else
diff --git a/libcxx/include/tgmath.h b/libcxx/include/tgmath.h
index 9249b8467c8507..49b98a530cd659 100644
--- a/libcxx/include/tgmath.h
+++ b/libcxx/include/tgmath.h
@@ -25,8 +25,8 @@
 
 #ifdef __cplusplus
 #  if _LIBCPP_STD_VER >= 17
-#    include <complex>
 #    include <cmath>
+#    include <complex>
 #  else
 #    include <ctgmath>
 #  endif



More information about the llvm-commits mailing list