KEMBAR78
Avoiding __builtin_strlen by brevzin · Pull Request #4429 · fmtlib/fmt · GitHub
Skip to content

Conversation

@brevzin
Copy link
Contributor

@brevzin brevzin commented Apr 26, 2025

The added test fails on gcc 14 because of the call to __builtin_strlen, so just avoiding it during constant evaluation. Fixed #4423.

Copy link
Contributor

@vitaut vitaut left a 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.

@brevzin
Copy link
Contributor Author

brevzin commented Apr 26, 2025

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.

#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));
Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

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.

@vitaut vitaut merged commit 8978ab0 into fmtlib:master Apr 27, 2025
45 checks passed
@vitaut
Copy link
Contributor

vitaut commented Apr 27, 2025

Merged, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Don't use __builtin_strlen

3 participants