Skip to content

[libc++] Annotate generic_category/system_category as const #78052

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

Merged
merged 1 commit into from
Jan 26, 2024
Merged

Conversation

d0k
Copy link
Member

@d0k d0k commented Jan 13, 2024

This lets the compiler eliminate unused/duplicate calls to it.

@d0k d0k requested a review from a team as a code owner January 13, 2024 17:26
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Jan 13, 2024
@llvmbot
Copy link
Member

llvmbot commented Jan 13, 2024

@llvm/pr-subscribers-libcxx

Author: Benjamin Kramer (d0k)

Changes

This lets the compiler eliminate unused/duplicate calls to it.


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

1 Files Affected:

  • (modified) libcxx/include/__system_error/error_category.h (+2-2)
diff --git a/libcxx/include/__system_error/error_category.h b/libcxx/include/__system_error/error_category.h
index 11c920e32657c2..7233e221104471 100644
--- a/libcxx/include/__system_error/error_category.h
+++ b/libcxx/include/__system_error/error_category.h
@@ -67,8 +67,8 @@ class _LIBCPP_HIDDEN __do_message : public error_category {
   string message(int __ev) const override;
 };
 
-_LIBCPP_EXPORTED_FROM_ABI const error_category& generic_category() _NOEXCEPT;
-_LIBCPP_EXPORTED_FROM_ABI const error_category& system_category() _NOEXCEPT;
+[[__gnu__::__const__]] _LIBCPP_EXPORTED_FROM_ABI const error_category& generic_category() _NOEXCEPT;
+[[__gnu__::__const__]] _LIBCPP_EXPORTED_FROM_ABI const error_category& system_category() _NOEXCEPT;
 
 _LIBCPP_END_NAMESPACE_STD
 

@ldionne
Copy link
Member

ldionne commented Jan 23, 2024

CI doesn't seem happy: https://buildkite.com/llvm-project/libcxx-ci/builds/32831#018d03dd-6965-4ebd-a7b6-7d6b9ec5d619

I wonder if this is just the AppleClang bots using a slightly older compiler?

@d0k
Copy link
Member Author

d0k commented Jan 23, 2024

CI doesn't seem happy: https://buildkite.com/llvm-project/libcxx-ci/builds/32831#018d03dd-6965-4ebd-a7b6-7d6b9ec5d619

I wonder if this is just the AppleClang bots using a slightly older compiler?

Looks like it's compiling with -std=c++03 and doesn't like [[attribute]] syntax. Should it be compiling system_error.h in C++03 mode? Seens to be coming from <ios>.

@ldionne
Copy link
Member

ldionne commented Jan 23, 2024

I see two options:

  1. Use an alternative attribute syntax that works in C++03 mode
  2. Don't provide <system_error> in C++03 mode, since it is technically a C++11 addition to the library

(2) is a lot harder and would be breaking for users. We could investigate doing that, but (1) would be significantly easier especially given the simplicity of the patch that motivates it.

This lets the compiler eliminate unused/duplicate calls to it.
@d0k
Copy link
Member Author

d0k commented Jan 25, 2024

Changed it to use GNU __attribute__(__const__).

@d0k d0k merged commit 3fa1423 into llvm:main Jan 26, 2024
@d0k d0k deleted the const branch January 26, 2024 21:08
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. performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants