[libcxx-commits] [libcxx] [libc++] __uglify `[[clang::noescape]]` (PR #113280)

A. Jiang via libcxx-commits libcxx-commits at lists.llvm.org
Tue Oct 22 17:52:57 PDT 2024


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

>From 3a0dba91d94eaa02fc921815001e8321db2b8ea1 Mon Sep 17 00:00:00 2001
From: "A. Jiang" <de34 at live.cn>
Date: Tue, 22 Oct 2024 17:07:36 +0800
Subject: [PATCH 1/2] [libc++] __uglify `[[clang::noescape]]`

Identifiers `clang` and `noescape` are not reserved by the C++ standard,
so perhaps we need to use the equivalent reserved forms.

Also changes the occurrences of that attribute to a macro, following the
convention for `[[_Clang::__lifetimebound__]]`.
---
 libcxx/include/__charconv/from_chars_floating_point.h | 6 +++---
 libcxx/include/__config                               | 6 ++++++
 libcxx/src/charconv.cpp                               | 6 +++---
 libcxx/test/libcxx/system_reserved_names.gen.py       | 4 ++++
 4 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/libcxx/include/__charconv/from_chars_floating_point.h b/libcxx/include/__charconv/from_chars_floating_point.h
index 2860b0e8da83af..5cd3fc4a41ea1d 100644
--- a/libcxx/include/__charconv/from_chars_floating_point.h
+++ b/libcxx/include/__charconv/from_chars_floating_point.h
@@ -37,13 +37,13 @@ struct __from_chars_result {
 
 template <class _Fp>
 _LIBCPP_EXPORTED_FROM_ABI __from_chars_result<_Fp> __from_chars_floating_point(
-    [[clang::noescape]] const char* __first, [[clang::noescape]] const char* __last, chars_format __fmt);
+    _LIBCPP_NOESCAPE const char* __first, _LIBCPP_NOESCAPE const char* __last, chars_format __fmt);
 
 extern template __from_chars_result<float> __from_chars_floating_point(
-    [[clang::noescape]] const char* __first, [[clang::noescape]] const char* __last, chars_format __fmt);
+    _LIBCPP_NOESCAPE const char* __first, _LIBCPP_NOESCAPE const char* __last, chars_format __fmt);
 
 extern template __from_chars_result<double> __from_chars_floating_point(
-    [[clang::noescape]] const char* __first, [[clang::noescape]] const char* __last, chars_format __fmt);
+    _LIBCPP_NOESCAPE const char* __first, _LIBCPP_NOESCAPE const char* __last, chars_format __fmt);
 
 template <class _Fp>
 _LIBCPP_HIDE_FROM_ABI from_chars_result
diff --git a/libcxx/include/__config b/libcxx/include/__config
index fcba56f7e3d5b1..fca1a01851e81e 100644
--- a/libcxx/include/__config
+++ b/libcxx/include/__config
@@ -1167,6 +1167,12 @@ typedef __char32_t char32_t;
 #    define _LIBCPP_LIFETIMEBOUND
 #  endif
 
+#  if __has_cpp_attribute(_Clang::__noescape__)
+#    define _LIBCPP_NOESCAPE [[_Clang::__noescape__]]
+#  else
+#    define _LIBCPP_NOESCAPE
+#  endif
+
 #  if __has_attribute(__nodebug__)
 #    define _LIBCPP_NODEBUG __attribute__((__nodebug__))
 #  else
diff --git a/libcxx/src/charconv.cpp b/libcxx/src/charconv.cpp
index 3fe0afec0e283c..5e8cb7d97703b4 100644
--- a/libcxx/src/charconv.cpp
+++ b/libcxx/src/charconv.cpp
@@ -77,13 +77,13 @@ to_chars_result to_chars(char* __first, char* __last, long double __value, chars
 
 template <class _Fp>
 __from_chars_result<_Fp> __from_chars_floating_point(
-    [[clang::noescape]] const char* __first, [[clang::noescape]] const char* __last, chars_format __fmt) {
+    _LIBCPP_NOESCAPE const char* __first, _LIBCPP_NOESCAPE const char* __last, chars_format __fmt) {
   return std::__from_chars_floating_point_impl<_Fp>(__first, __last, __fmt);
 }
 
 template __from_chars_result<float> __from_chars_floating_point(
-    [[clang::noescape]] const char* __first, [[clang::noescape]] const char* __last, chars_format __fmt);
+    _LIBCPP_NOESCAPE const char* __first, _LIBCPP_NOESCAPE const char* __last, chars_format __fmt);
 
 template __from_chars_result<double> __from_chars_floating_point(
-    [[clang::noescape]] const char* __first, [[clang::noescape]] const char* __last, chars_format __fmt);
+    _LIBCPP_NOESCAPE const char* __first, _LIBCPP_NOESCAPE const char* __last, chars_format __fmt);
 _LIBCPP_END_NAMESPACE_STD
diff --git a/libcxx/test/libcxx/system_reserved_names.gen.py b/libcxx/test/libcxx/system_reserved_names.gen.py
index e29e7a2cdd6144..666b28f79d37b7 100644
--- a/libcxx/test/libcxx/system_reserved_names.gen.py
+++ b/libcxx/test/libcxx/system_reserved_names.gen.py
@@ -154,6 +154,10 @@
 #define Xp SYSTEM_RESERVED_NAME
 #define Xs SYSTEM_RESERVED_NAME
 
+// These attribute-tokens are not reserved, so the user can macro-define them.
+#define lifetimebound SYSTEM_RESERVED_NAME
+#define noescape SYSTEM_RESERVED_NAME
+
 // The classic Windows min/max macros
 #define min SYSTEM_RESERVED_NAME
 #define max SYSTEM_RESERVED_NAME

>From d4a9f0dc20cc3a1825a36e2b741369892519d373 Mon Sep 17 00:00:00 2001
From: "A. Jiang" <de34 at live.cn>
Date: Wed, 23 Oct 2024 08:52:47 +0800
Subject: [PATCH 2/2] Revert changes of system_reserved_names.gen.py

---
 libcxx/test/libcxx/system_reserved_names.gen.py | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/libcxx/test/libcxx/system_reserved_names.gen.py b/libcxx/test/libcxx/system_reserved_names.gen.py
index 666b28f79d37b7..e29e7a2cdd6144 100644
--- a/libcxx/test/libcxx/system_reserved_names.gen.py
+++ b/libcxx/test/libcxx/system_reserved_names.gen.py
@@ -154,10 +154,6 @@
 #define Xp SYSTEM_RESERVED_NAME
 #define Xs SYSTEM_RESERVED_NAME
 
-// These attribute-tokens are not reserved, so the user can macro-define them.
-#define lifetimebound SYSTEM_RESERVED_NAME
-#define noescape SYSTEM_RESERVED_NAME
-
 // The classic Windows min/max macros
 #define min SYSTEM_RESERVED_NAME
 #define max SYSTEM_RESERVED_NAME



More information about the libcxx-commits mailing list