Skip to content

Conversation

iidmsa
Copy link
Contributor

@iidmsa iidmsa commented Sep 21, 2025

The FIXME comment about not hardcoding table_size is unclear about its
original intent.

@iidmsa iidmsa requested a review from a team as a code owner September 21, 2025 20:11
Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Sep 21, 2025
@llvmbot
Copy link
Member

llvmbot commented Sep 21, 2025

@llvm/pr-subscribers-libcxx

Author: Fady Farag (iidmsa)

Changes

Fix by computing table_size as 1 << CHAR_BIT instead of hardcoding 256.


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

1 Files Affected:

  • (modified) libcxx/include/__cxx03/__locale (+1-1)
diff --git a/libcxx/include/__cxx03/__locale b/libcxx/include/__cxx03/__locale
index 86160bcdcbd59..d30de94b127cf 100644
--- a/libcxx/include/__cxx03/__locale
+++ b/libcxx/include/__cxx03/__locale
@@ -578,7 +578,7 @@ public:
 #ifdef _CACHED_RUNES
   static const size_t table_size = _CACHED_RUNES;
 #else
-  static const size_t table_size = 256; // FIXME: Don't hardcode this.
+  static const size_t table_size = 1 << CHAR_BIT;
 #endif
   _LIBCPP_HIDE_FROM_ABI const mask* table() const _NOEXCEPT { return __tab_; }
   static const mask* classic_table() _NOEXCEPT;

Copy link
Contributor

@philnik777 philnik777 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that was the intention behind the comment, but I'm also not sure what it was. I'm also not convinced that the new code is any more readable than the previous implementation, so IMO it'd be better to simply drop the comment.
(Unless @HowardHinnant or @jyasskin possibly remembers what the intention here was?)

@HowardHinnant
Copy link

I don't recall for sure.

@jyasskin
Copy link
Contributor

I don't either.

The FIXME comment about not hardcoding table_size is unclear about its
original intent.
@iidmsa iidmsa force-pushed the fix-ctype-table-size branch from 7767c34 to 9b659fa Compare September 22, 2025 17:12
@iidmsa iidmsa changed the title [libc++] Replace hardcoded table_size with CHAR_BIT calculation [libc++] Remove outdated FIXME comment in ctype<char> Sep 22, 2025
@iidmsa
Copy link
Contributor Author

iidmsa commented Sep 22, 2025

I don't think that was the intention behind the comment, but I'm also not sure what it was. I'm also not convinced that the new code is any more readable than the previous implementation, so IMO it'd be better to simply drop the comment. (Unless @HowardHinnant or @jyasskin possibly remembers what the intention here was?)

Thank you very much for the comment. I dropped the FIXME comment for both frozen and non-frozen headers.

@iidmsa
Copy link
Contributor Author

iidmsa commented Sep 22, 2025

I don't recall for sure.

Thank you for your comment.

@iidmsa
Copy link
Contributor Author

iidmsa commented Sep 22, 2025

I don't either.

Thank you for your comment.

Copy link
Contributor

@philnik777 philnik777 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have commit access?

@iidmsa
Copy link
Contributor Author

iidmsa commented Sep 23, 2025

Do you have commit access?

No, this is my very first PR to LLVM.

@philnik777
Copy link
Contributor

@iidmsa Please make your Email public (see https://llvm.org/docs/DeveloperPolicy.html#email-addresses).

@iidmsa
Copy link
Contributor Author

iidmsa commented Sep 23, 2025

@iidmsa Please make your Email public (see https://llvm.org/docs/DeveloperPolicy.html#email-addresses).

Done.

@philnik777 philnik777 merged commit 32ff987 into llvm:main Sep 23, 2025
73 of 75 checks passed
Copy link

@iidmsa Congratulations on having your first Pull Request (PR) merged into the LLVM Project!

Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail here.

If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are working as expected, well done!

YixingZhang007 pushed a commit to YixingZhang007/llvm-project that referenced this pull request Sep 27, 2025
The FIXME comment about not hardcoding table_size is unclear about its
original intent.
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.

6 participants