Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[libc++] __uglify [[clang::noescape]] #113280

Merged
merged 2 commits into from
Oct 25, 2024

Conversation

frederick-vs-ja
Copy link
Contributor

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__]].

Addresses #91651 (comment).

@frederick-vs-ja frederick-vs-ja requested a review from a team as a code owner October 22, 2024 08:37
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Oct 22, 2024
@llvmbot
Copy link
Member

llvmbot commented Oct 22, 2024

@llvm/pr-subscribers-libcxx

Author: A. Jiang (frederick-vs-ja)

Changes

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__]].

Addresses #91651 (comment).


Full diff: https://github.com/llvm/llvm-project/pull/113280.diff

4 Files Affected:

  • (modified) libcxx/include/__charconv/from_chars_floating_point.h (+3-3)
  • (modified) libcxx/include/__config (+6)
  • (modified) libcxx/src/charconv.cpp (+3-3)
  • (modified) libcxx/test/libcxx/system_reserved_names.gen.py (+5)
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..f3ded81cb0a2d6 100644
--- a/libcxx/test/libcxx/system_reserved_names.gen.py
+++ b/libcxx/test/libcxx/system_reserved_names.gen.py
@@ -154,6 +154,11 @@
 #define Xp SYSTEM_RESERVED_NAME
 #define Xs SYSTEM_RESERVED_NAME
 
+// These attribute-tokens are not reserved, so the user can macro-define them.
+#define clang SYSTEM_RESERVED_NAME
+#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

@frederick-vs-ja

This comment was marked as resolved.

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__]]`.
@ldionne
Copy link
Member

ldionne commented Oct 22, 2024

Oops... I must had ignored the following comments. @ldionne are you also working on such a macro? Perhaps this PR should be closed if so.

No, I don't have a patch yet. I just wanted to add documentation that can reference that macro.

@frederick-vs-ja frederick-vs-ja merged commit 08159e6 into llvm:main Oct 25, 2024
63 checks passed
@frederick-vs-ja frederick-vs-ja deleted the _Clang-__noescape__ branch October 25, 2024 01:04
@frobtech frobtech mentioned this pull request Oct 25, 2024
NoumanAmir657 pushed a commit to NoumanAmir657/llvm-project that referenced this pull request Nov 4, 2024
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__]]`.

Addresses
llvm#91651 (comment).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants