This is an archive of the discontinued LLVM Phabricator instance.

[libc++] Simplify the char_traits specializations
ClosedPublic

Authored by philnik on Jun 6 2022, 3:22 PM.

Details

Diff Detail

Event Timeline

philnik created this revision.Jun 6 2022, 3:22 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 6 2022, 3:23 PM
philnik requested review of this revision.Jun 6 2022, 3:23 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 6 2022, 3:23 PM
Herald added a reviewer: Restricted Project. · View Herald Transcript
mclow.lists added inline comments.
libcxx/include/__string/char_traits.h
226

Does this handle overlapping ranges? The old code does.

https://eel.is/c++draft/char.traits.require says it has to handle overlapping ranges.

philnik marked an inline comment as done.Jun 6 2022, 4:02 PM
philnik added inline comments.
libcxx/include/__string/char_traits.h
226

While std::copy_n doesn't officially support overlapping ranges our implementation forwards trivial types to __builtin_memmove, which does handle them properly.

ldionne requested changes to this revision.Jun 9 2022, 9:08 AM
ldionne added inline comments.
libcxx/include/__string/char_traits.h
226

Can you please add tests to cover that (or ensure we already do)?

Also, if we keep this, let's add a comment like // our implementation of std::copy_n handles overlapping ranges.

This revision now requires changes to proceed.Jun 9 2022, 9:08 AM
EricWF added a subscriber: EricWF.Jun 9 2022, 1:26 PM
EricWF added inline comments.
libcxx/include/__string/char_traits.h
545–548

Don't we externally instantiate char_traits? This change would allow the compiler to instantiate and generate code in each TU for these functions. Maybe that's what we want, maybe that isn't. But we should consider it.

philnik updated this revision to Diff 436337.Jun 13 2022, 4:07 AM
philnik marked an inline comment as done.
  • GCC doesn't support __builtin_memmove during constant evaluation
philnik added inline comments.Jun 13 2022, 4:07 AM
libcxx/include/__string/char_traits.h
545–548

All the functions are marked _LIBCPP_INLINE_VISIBILITY? Even if we had an extern template they wouldn't be part of it.

ldionne accepted this revision.Jun 13 2022, 8:45 AM

LGTM with comments.

libcxx/include/__string/char_traits.h
181–183
226

My comment about testing for overlapping ranges still holds. It should be simple to add.

This revision is now accepted and ready to land.Jun 13 2022, 8:45 AM
philnik updated this revision to Diff 436430.Jun 13 2022, 8:54 AM
philnik marked 4 inline comments as done.
  • Address comments
  • Rename __move_constexpr to __char_traits_move
philnik added inline comments.Jun 13 2022, 10:38 AM
libcxx/include/__string/char_traits.h
181–183

This would break the implementation. This part of the code is still used if __move_constexpr isn't constant-evaluated. I probably should rename __move_constexpr to something better.

226

Sorry, I should have left a comment. That's already tested.

This revision was landed with ongoing or failed builds.Jun 13 2022, 12:38 PM
This revision was automatically updated to reflect the committed changes.