[libcxx-commits] [libcxx] e8cb355 - [libc++] Move constexpr <cstring> functions into their own headers and remove unused <cstring> includes
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Feb 21 07:56:38 PST 2023
Author: Nikolas Klauser
Date: 2023-02-21T16:56:29+01:00
New Revision: e8cb3559eec0d0b182fa01e6e35183025f9143a3
URL: https://github.com/llvm/llvm-project/commit/e8cb3559eec0d0b182fa01e6e35183025f9143a3
DIFF: https://github.com/llvm/llvm-project/commit/e8cb3559eec0d0b182fa01e6e35183025f9143a3.diff
LOG: [libc++] Move constexpr <cstring> functions into their own headers and remove unused <cstring> includes
Reviewed By: ldionne, Mordante, #libc, #libc_abi
Spies: libcxx-commits
Differential Revision: https://reviews.llvm.org/D143329
Added:
libcxx/include/__string/constexpr_c_functions.h
Modified:
libcxx/docs/ReleaseNotes.rst
libcxx/include/CMakeLists.txt
libcxx/include/__bit_reference
libcxx/include/__format/format_arg_store.h
libcxx/include/__string/char_traits.h
libcxx/include/charconv
libcxx/include/chrono
libcxx/include/cstring
libcxx/include/fstream
libcxx/include/module.modulemap.in
libcxx/include/regex
libcxx/src/include/ryu/common.h
libcxx/test/libcxx/private_headers.verify.cpp
libcxx/test/libcxx/strings/c.strings/constexpr.cstring.compile.pass.cpp
libcxx/test/libcxx/transitive_includes/cxx03.csv
libcxx/test/libcxx/transitive_includes/cxx11.csv
libcxx/test/libcxx/transitive_includes/cxx14.csv
libcxx/test/libcxx/transitive_includes/cxx17.csv
libcxx/test/libcxx/transitive_includes/cxx20.csv
libcxx/test/libcxx/transitive_includes/cxx2b.csv
libcxxabi/test/test_demangle.pass.cpp
Removed:
################################################################################
diff --git a/libcxx/docs/ReleaseNotes.rst b/libcxx/docs/ReleaseNotes.rst
index 5c2e2266b6815..acd5c16070323 100644
--- a/libcxx/docs/ReleaseNotes.rst
+++ b/libcxx/docs/ReleaseNotes.rst
@@ -57,7 +57,7 @@ Deprecations and Removals
includes are removed based on the language version used. Incidental transitive
inclusions of the following headers have been removed:
- - C++2b: ``bit``, ``type_traits``
+ - C++2b: ``bit``, ``cstring``, ``type_traits``
Upcoming Deprecations and Removals
----------------------------------
diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index c2496bcb2fb0e..7a62cc951a6d1 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -557,6 +557,7 @@ set(files
__split_buffer
__std_stream
__string/char_traits.h
+ __string/constexpr_c_functions.h
__string/extern_template_lists.h
__support/android/locale_bionic.h
__support/fuchsia/xlocale.h
diff --git a/libcxx/include/__bit_reference b/libcxx/include/__bit_reference
index c5748a2833268..8b498cd16dc86 100644
--- a/libcxx/include/__bit_reference
+++ b/libcxx/include/__bit_reference
@@ -19,7 +19,6 @@
#include <__iterator/iterator_traits.h>
#include <__memory/construct_at.h>
#include <__memory/pointer_traits.h>
-#include <cstring>
#include <type_traits>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
diff --git a/libcxx/include/__format/format_arg_store.h b/libcxx/include/__format/format_arg_store.h
index e975ce148f7f2..9791fb6b96abc 100644
--- a/libcxx/include/__format/format_arg_store.h
+++ b/libcxx/include/__format/format_arg_store.h
@@ -20,7 +20,6 @@
#include <__format/concepts.h>
#include <__format/format_arg.h>
#include <__utility/forward.h>
-#include <cstring>
#include <string>
#include <string_view>
#include <type_traits>
diff --git a/libcxx/include/__string/char_traits.h b/libcxx/include/__string/char_traits.h
index 6f2fc7a685d13..9d962425bbb68 100644
--- a/libcxx/include/__string/char_traits.h
+++ b/libcxx/include/__string/char_traits.h
@@ -18,11 +18,11 @@
#include <__config>
#include <__functional/hash.h>
#include <__iterator/iterator_traits.h>
+#include <__string/constexpr_c_functions.h>
#include <__type_traits/is_constant_evaluated.h>
#include <cstddef>
#include <cstdint>
#include <cstdio>
-#include <cstring>
#include <iosfwd>
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
diff --git a/libcxx/include/__string/constexpr_c_functions.h b/libcxx/include/__string/constexpr_c_functions.h
new file mode 100644
index 0000000000000..927b823997525
--- /dev/null
+++ b/libcxx/include/__string/constexpr_c_functions.h
@@ -0,0 +1,71 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___STRING_CONSTEXPR_C_FUNCTIONS_H
+#define _LIBCPP___STRING_CONSTEXPR_C_FUNCTIONS_H
+
+#include <__config>
+#include <__type_traits/is_constant_evaluated.h>
+#include <cstddef>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+# pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 size_t __constexpr_strlen(const char* __str) {
+ // GCC currently doesn't support __builtin_strlen for heap-allocated memory during constant evaluation.
+ // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70816
+#ifdef _LIBCPP_COMPILER_GCC
+ if (__libcpp_is_constant_evaluated()) {
+ size_t __i = 0;
+ for (; __str[__i] != '\0'; ++__i)
+ ;
+ return __i;
+ }
+#endif
+ return __builtin_strlen(__str);
+}
+
+template <class _Tp>
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 int
+__constexpr_memcmp(const _Tp* __lhs, const _Tp* __rhs, size_t __count) {
+#ifdef _LIBCPP_COMPILER_GCC
+ if (__libcpp_is_constant_evaluated()) {
+ for (; __count; --__count, ++__lhs, ++__rhs) {
+ if (*__lhs < *__rhs)
+ return -1;
+ if (*__rhs < *__lhs)
+ return 1;
+ }
+ return 0;
+ }
+#endif
+ return __builtin_memcmp(__lhs, __rhs, __count);
+}
+
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const char*
+__constexpr_char_memchr(const char* __str, int __char, size_t __count) {
+#if __has_builtin(__builtin_char_memchr)
+ return __builtin_char_memchr(__str, __char, __count);
+#else
+ if (!__libcpp_is_constant_evaluated())
+ return static_cast<const char*>(__builtin_memchr(__str, __char, __count));
+ for (; __count; --__count) {
+ if (*__str == __char)
+ return __str;
+ ++__str;
+ }
+ return nullptr;
+#endif
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___STRING_CONSTEXPR_C_FUNCTIONS_H
diff --git a/libcxx/include/charconv b/libcxx/include/charconv
index d66aaad701b52..df444d7e7a289 100644
--- a/libcxx/include/charconv
+++ b/libcxx/include/charconv
@@ -85,7 +85,6 @@ namespace std {
#include <cmath> // for log2f
#include <cstdint>
#include <cstdlib>
-#include <cstring>
#include <limits>
#include <type_traits>
@@ -831,6 +830,7 @@ _LIBCPP_POP_MACROS
#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
# include <concepts>
+# include <cstring>
# include <iosfwd>
#endif
diff --git a/libcxx/include/chrono b/libcxx/include/chrono
index 2ecd6d4360cda..7593e947ed623 100644
--- a/libcxx/include/chrono
+++ b/libcxx/include/chrono
@@ -790,6 +790,7 @@ constexpr chrono::year operator ""y(unsigned lo
#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
# include <bit>
# include <concepts>
+# include <cstring>
#endif
#endif // _LIBCPP_CHRONO
diff --git a/libcxx/include/cstring b/libcxx/include/cstring
index c88d97739f744..a9bdf4ff2dfca 100644
--- a/libcxx/include/cstring
+++ b/libcxx/include/cstring
@@ -100,53 +100,6 @@ using ::memset _LIBCPP_USING_IF_EXISTS;
using ::strerror _LIBCPP_USING_IF_EXISTS;
using ::strlen _LIBCPP_USING_IF_EXISTS;
-inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 size_t __constexpr_strlen(const char* __str) {
- // GCC currently doesn't support __builtin_strlen for heap-allocated memory during constant evaluation.
- // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70816
-#ifdef _LIBCPP_COMPILER_GCC
- if (__libcpp_is_constant_evaluated()) {
- size_t __i = 0;
- for (; __str[__i] != '\0'; ++__i)
- ;
- return __i;
- }
-#endif
- return __builtin_strlen(__str);
-}
-
-template <class _Tp>
-_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 int
-__constexpr_memcmp(const _Tp* __lhs, const _Tp* __rhs, size_t __count) {
-#ifdef _LIBCPP_COMPILER_GCC
- if (__libcpp_is_constant_evaluated()) {
- for (; __count; --__count, ++__lhs, ++__rhs) {
- if (*__lhs < *__rhs)
- return -1;
- if (*__rhs < *__lhs)
- return 1;
- }
- return 0;
- }
-#endif
- return __builtin_memcmp(__lhs, __rhs, __count);
-}
-
-inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const char*
-__constexpr_char_memchr(const char* __str, int __char, size_t __count) {
-#if __has_builtin(__builtin_char_memchr)
- return __builtin_char_memchr(__str, __char, __count);
-#else
- if (!__libcpp_is_constant_evaluated())
- return static_cast<const char*>(std::memchr(__str, __char, __count));
- for (; __count; --__count) {
- if (*__str == __char)
- return __str;
- ++__str;
- }
- return nullptr;
-#endif
-}
-
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_CSTRING
diff --git a/libcxx/include/fstream b/libcxx/include/fstream
index 98094d8757ea9..b38b25567c50b 100644
--- a/libcxx/include/fstream
+++ b/libcxx/include/fstream
@@ -189,7 +189,6 @@ typedef basic_fstream<wchar_t> wfstream;
#include <__utility/unreachable.h>
#include <cstdio>
#include <cstdlib>
-#include <cstring>
#include <istream>
#include <ostream>
#include <typeinfo>
diff --git a/libcxx/include/module.modulemap.in b/libcxx/include/module.modulemap.in
index 406e48179b9b3..10b2c4f3d9b89 100644
--- a/libcxx/include/module.modulemap.in
+++ b/libcxx/include/module.modulemap.in
@@ -1380,6 +1380,7 @@ module std [system] {
export string_view
module __string {
module char_traits { private header "__string/char_traits.h" }
+ module constexpr_c_functions { private header "__string/constexpr_c_functions.h" }
module extern_template_lists { private header "__string/extern_template_lists.h" }
module string_fwd { private header "__fwd/string.h" }
}
diff --git a/libcxx/include/regex b/libcxx/include/regex
index 59c11f72051c7..15c2103f18b40 100644
--- a/libcxx/include/regex
+++ b/libcxx/include/regex
@@ -773,7 +773,6 @@ typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator;
#include <__utility/move.h>
#include <__utility/pair.h>
#include <__utility/swap.h>
-#include <cstring>
#include <deque>
#include <stdexcept>
#include <string>
diff --git a/libcxx/src/include/ryu/common.h b/libcxx/src/include/ryu/common.h
index a29b2436faf29..4503e6d35ac2c 100644
--- a/libcxx/src/include/ryu/common.h
+++ b/libcxx/src/include/ryu/common.h
@@ -43,7 +43,8 @@
// clang-format off
#include <__assert>
-#include "__config"
+#include <__config>
+#include <cstring>
_LIBCPP_BEGIN_NAMESPACE_STD
diff --git a/libcxx/test/libcxx/private_headers.verify.cpp b/libcxx/test/libcxx/private_headers.verify.cpp
index a6c1ef0ff9144..926448d05c3a2 100644
--- a/libcxx/test/libcxx/private_headers.verify.cpp
+++ b/libcxx/test/libcxx/private_headers.verify.cpp
@@ -588,6 +588,7 @@ END-SCRIPT
#include <__split_buffer> // expected-error@*:* {{use of private header from outside its module: '__split_buffer'}}
#include <__std_stream> // expected-error@*:* {{use of private header from outside its module: '__std_stream'}}
#include <__string/char_traits.h> // expected-error@*:* {{use of private header from outside its module: '__string/char_traits.h'}}
+#include <__string/constexpr_c_functions.h> // expected-error@*:* {{use of private header from outside its module: '__string/constexpr_c_functions.h'}}
#include <__string/extern_template_lists.h> // expected-error@*:* {{use of private header from outside its module: '__string/extern_template_lists.h'}}
#include <__thread/poll_with_backoff.h> // expected-error@*:* {{use of private header from outside its module: '__thread/poll_with_backoff.h'}}
#include <__thread/timed_backoff_policy.h> // expected-error@*:* {{use of private header from outside its module: '__thread/timed_backoff_policy.h'}}
diff --git a/libcxx/test/libcxx/strings/c.strings/constexpr.cstring.compile.pass.cpp b/libcxx/test/libcxx/strings/c.strings/constexpr.cstring.compile.pass.cpp
index ad078c0a21db4..f440810fb6f8a 100644
--- a/libcxx/test/libcxx/strings/c.strings/constexpr.cstring.compile.pass.cpp
+++ b/libcxx/test/libcxx/strings/c.strings/constexpr.cstring.compile.pass.cpp
@@ -8,9 +8,11 @@
// UNSUPPORTED: c++03, c++11
+// ADDITIONAL_COMPILE_FLAGS: -Wno-private-header
+
// Check that __constexpr_* cstring functions are actually constexpr
-#include <cstring>
+#include <__string/constexpr_c_functions.h>
static_assert(std::__constexpr_strlen("Banane") == 6, "");
static_assert(std::__constexpr_memcmp("Banane", "Banand", 6) == 1, "");
diff --git a/libcxx/test/libcxx/transitive_includes/cxx03.csv b/libcxx/test/libcxx/transitive_includes/cxx03.csv
index 7c25c6c40e145..ef8869dd30128 100644
--- a/libcxx/test/libcxx/transitive_includes/cxx03.csv
+++ b/libcxx/test/libcxx/transitive_includes/cxx03.csv
@@ -112,6 +112,7 @@ chrono concepts
chrono cstddef
chrono cstdint
chrono cstdlib
+chrono cstring
chrono ctime
chrono limits
chrono ratio
@@ -328,7 +329,6 @@ format charconv
format cstddef
format cstdint
format cstdlib
-format cstring
format initializer_list
format limits
format locale
diff --git a/libcxx/test/libcxx/transitive_includes/cxx11.csv b/libcxx/test/libcxx/transitive_includes/cxx11.csv
index ae3b789481fca..da29857edec63 100644
--- a/libcxx/test/libcxx/transitive_includes/cxx11.csv
+++ b/libcxx/test/libcxx/transitive_includes/cxx11.csv
@@ -112,6 +112,7 @@ chrono concepts
chrono cstddef
chrono cstdint
chrono cstdlib
+chrono cstring
chrono ctime
chrono limits
chrono ratio
@@ -328,7 +329,6 @@ format charconv
format cstddef
format cstdint
format cstdlib
-format cstring
format initializer_list
format limits
format locale
diff --git a/libcxx/test/libcxx/transitive_includes/cxx14.csv b/libcxx/test/libcxx/transitive_includes/cxx14.csv
index 4793bee34d16a..8181e80a0c481 100644
--- a/libcxx/test/libcxx/transitive_includes/cxx14.csv
+++ b/libcxx/test/libcxx/transitive_includes/cxx14.csv
@@ -112,6 +112,7 @@ chrono concepts
chrono cstddef
chrono cstdint
chrono cstdlib
+chrono cstring
chrono ctime
chrono limits
chrono ratio
@@ -330,7 +331,6 @@ format charconv
format cstddef
format cstdint
format cstdlib
-format cstring
format initializer_list
format limits
format locale
diff --git a/libcxx/test/libcxx/transitive_includes/cxx17.csv b/libcxx/test/libcxx/transitive_includes/cxx17.csv
index 4793bee34d16a..8181e80a0c481 100644
--- a/libcxx/test/libcxx/transitive_includes/cxx17.csv
+++ b/libcxx/test/libcxx/transitive_includes/cxx17.csv
@@ -112,6 +112,7 @@ chrono concepts
chrono cstddef
chrono cstdint
chrono cstdlib
+chrono cstring
chrono ctime
chrono limits
chrono ratio
@@ -330,7 +331,6 @@ format charconv
format cstddef
format cstdint
format cstdlib
-format cstring
format initializer_list
format limits
format locale
diff --git a/libcxx/test/libcxx/transitive_includes/cxx20.csv b/libcxx/test/libcxx/transitive_includes/cxx20.csv
index 092a0fdf79ce8..c422a9964aa0e 100644
--- a/libcxx/test/libcxx/transitive_includes/cxx20.csv
+++ b/libcxx/test/libcxx/transitive_includes/cxx20.csv
@@ -338,7 +338,6 @@ format charconv
format cstddef
format cstdint
format cstdlib
-format cstring
format initializer_list
format limits
format locale
diff --git a/libcxx/test/libcxx/transitive_includes/cxx2b.csv b/libcxx/test/libcxx/transitive_includes/cxx2b.csv
index b94bfbe4efd84..31c748064d8ae 100644
--- a/libcxx/test/libcxx/transitive_includes/cxx2b.csv
+++ b/libcxx/test/libcxx/transitive_includes/cxx2b.csv
@@ -68,7 +68,6 @@ charconv cmath
charconv cstddef
charconv cstdint
charconv cstdlib
-charconv cstring
charconv initializer_list
charconv limits
charconv type_traits
@@ -79,7 +78,6 @@ chrono compare
chrono cstddef
chrono cstdint
chrono cstdlib
-chrono cstring
chrono ctime
chrono initializer_list
chrono limits
@@ -258,7 +256,6 @@ format charconv
format cstddef
format cstdint
format cstdlib
-format cstring
format initializer_list
format limits
format locale
diff --git a/libcxxabi/test/test_demangle.pass.cpp b/libcxxabi/test/test_demangle.pass.cpp
index bbbbdce8e6c39..0607c4ef7efaa 100644
--- a/libcxxabi/test/test_demangle.pass.cpp
+++ b/libcxxabi/test/test_demangle.pass.cpp
@@ -19,6 +19,7 @@
#include <cassert>
#include <cstdio>
#include <cstdlib>
+#include <cstring>
#include <cxxabi.h>
#include <string>
@@ -30051,7 +30052,7 @@ const char* cases[][2] =
{"_Zcv1BIRT_EIS1_E", "operator B<><>"},
{"_ZN2FnIXgs4BaseEX4BaseEEEvv","void Fn<::Base, Base>()"},
-
+
{"_ZN2FnIXgsnw_iEEXna_ipiLi4EEEEEvv", "void Fn<::new int, new[] int(4)>()"},
{"_ZN2FnIXnwLj4E_iEEXgsnaLj4E_ipiLi4EEEEEvv", "void Fn<new(4u) int, ::new[](4u) int(4)>()"},
{"_ZN2FnIXgsdlLi4EEXdaLi4EEEEvv", "void Fn<::delete 4, delete[] 4>()"},
More information about the libcxx-commits
mailing list