-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Avoiding __builtin_strlen #4429
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! The change LGTM but please move the test to base-test
and check the actual API being changed, namely basic_string_view
's ctor.
Makes sense, done. |
@@ -539,7 +539,7 @@ template <typename Char> class basic_string_view { | |||
#endif | |||
FMT_CONSTEXPR20 basic_string_view(const Char* s) : data_(s) { | |||
#if FMT_HAS_BUILTIN(__builtin_strlen) || FMT_GCC_VERSION || FMT_CLANG_VERSION | |||
if (std::is_same<Char, char>::value) { | |||
if (std::is_same<Char, char>::value && !detail::is_constant_evaluated()) { | |||
size_ = __builtin_strlen(detail::narrow(s)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the advantage of still using __builtin_strlen
? Will gcc or clang still end up producing a constant in some scenarios that they wouldn't if just strlen
was used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well... libstdc++ __builtin_strlen in char_traits, so I guess there's that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was some benefit to the debug codegen at some point but probably no longer matters on newer compilers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More importantly, strlen
is not constexpr.
Merged, thanks! |
The added test fails on gcc 14 because of the call to
__builtin_strlen
, so just avoiding it during constant evaluation. Fixed #4423.