This is an archive of the discontinued LLVM Phabricator instance.

[libc++] Simplify the string structures a bit more
ClosedPublic

Authored by philnik on May 12 2022, 12:43 PM.

Details

Summary

This simplifies the string structs a bit more and the normal layout should not contain any undefined behaviour anymore. I don't think there is a way to achieve this in the alternate string mode without breaking the ABI.

Diff Detail

Event Timeline

philnik created this revision.May 12 2022, 12:43 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 12 2022, 12:43 PM
philnik requested review of this revision.May 12 2022, 12:43 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 12 2022, 12:43 PM
Herald added a reviewer: Restricted Project. · View Herald Transcript
ldionne accepted this revision.May 13 2022, 9:39 AM

Other than my comment, LGTM.

libcxx/include/string
737–739

Here and above, we assume that 7+1 == 8 == CHAR_BIT, since the padding could potentially be wrong if that were not the case. I think this is a pre-existing condition, but I would suggest asserting it. Basically, I think our implementation doesn't support systems where CHAR_BIT != 8. WDYT?

This revision is now accepted and ready to land.May 13 2022, 9:39 AM
philnik updated this revision to Diff 429434.May 14 2022, 3:40 AM
philnik marked an inline comment as done.
  • Add assertion
This revision was automatically updated to reflect the committed changes.
hubert.reinterpretcast added inline comments.
libcxx/include/string
739

Is it really okay if the expression evaluates to zero?

philnik marked an inline comment as done.May 20 2022, 1:19 AM
philnik added inline comments.
libcxx/include/string
739

Clang and GCC allow arrays with zero size. https://godbolt.org/z/ddPMThYMz

ayzhao added a subscriber: ayzhao.Jun 10 2022, 6:19 PM

Chrome is observing failures on Windows caused by this patch: https://crbug.com/1334441

Mordante added inline comments.Jun 11 2022, 10:56 AM
libcxx/include/string
694

When you fix this can you add an static_assert that validates the size of the struct?

Chrome is observing failures on Windows caused by this patch: https://crbug.com/1334441

I will note this patch fixes an ABI break on AIX caused by https://reviews.llvm.org/D123580.

philnik marked an inline comment as done.Jun 11 2022, 11:27 AM

Chrome is observing failures on Windows caused by this patch: https://crbug.com/1334441

I will note this patch fixes an ABI break on AIX caused by https://reviews.llvm.org/D123580.

Do you want to tell me that using size_type is correct for AIX and unsigned char is correct for Windows?

Do you want to tell me that using size_type is correct for AIX and unsigned char is correct for Windows?

No, I was pointing out that a plain revert would be problematic. If the proposal is to change the type of the bit-fields to unsigned char, then that should be compatible on AIX as well.