This is an archive of the discontinued LLVM Phabricator instance.

[libc++] Make sure __clear_and_shrink() maintains string invariants
ClosedPublic

Authored by ldionne on Oct 5 2020, 1:18 PM.

Details

Summary

__clear_and_shrink() was added in D41976, and a test was added alongside
it to make sure that the string invariants were maintained. However, it
appears that the test never ran under UBSan before, which would have
highlighted the fact that it doesn't actually maintain the string
invariants.

Diff Detail

Event Timeline

ldionne created this revision.Oct 5 2020, 1:18 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 5 2020, 1:18 PM
Herald added a reviewer: Restricted Project. · View Herald Transcript
ldionne requested review of this revision.Oct 5 2020, 1:18 PM

Adding folks who worked on D41976.

vsk added a comment.Oct 5 2020, 2:36 PM

Looks reasonable to me, but I'm not comfortable lgtm'ing as I know too little about the string ABI.

It's interesting that UBSan flagged the issue. What diagnostic did you see?

libcxx/include/string
3962

__invariants checks that data()[0] == value_type(0) -- is this guaranteed to be equal to value_type()?

ldionne updated this revision to Diff 296307.Oct 5 2020, 3:00 PM

Use value_type() when checking invariants.

ldionne marked an inline comment as done.Oct 5 2020, 3:00 PM
ldionne added inline comments.
libcxx/include/string
3962

It looks to me like the invariants check is the odd one out here, since we use value_type() everywhere else.

ldionne accepted this revision.Oct 7 2020, 6:16 AM
ldionne marked an inline comment as done.
This revision is now accepted and ready to land.Oct 7 2020, 6:16 AM