__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.
Details
Details
- Reviewers
tvanslyke vsk ldionne - Group Reviewers
Restricted Project - Commits
- rG602c193e2aeb: [libc++] Make sure __clear_and_shrink() maintains string invariants
Diff Detail
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Comment Actions
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()? |
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. |
__invariants checks that data()[0] == value_type(0) -- is this guaranteed to be equal to value_type()?