This is an archive of the discontinued LLVM Phabricator instance.

[Demangle] avoid more std::string_view::substr
ClosedPublic

Authored by nickdesaulniers on May 23 2023, 2:39 PM.

Details

Summary

In D148959, I removed usage of std::string_view::substr because it may
throw, and libcxxabi cannot use such code. I missed one instance in
llvm::starts_with. That is blocking copying the code back upstream in
D148566.

Mark these helpers noexcept (as they are in C++20) as well, to remind
future travelers.

Make these changes upstream, and copy them back downstream using
libcxxabi/src/demangle/cp-to-llvm.sh.

Diff Detail

Event Timeline

Herald added a project: Restricted Project. · View Herald TranscriptMay 23 2023, 2:39 PM
nickdesaulniers requested review of this revision.May 23 2023, 2:39 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptMay 23 2023, 2:39 PM
Herald added a reviewer: Restricted Project. · View Herald Transcript
libcxxabi/src/demangle/StringViewExtras.h
24–25

front is not noexcept. Should I rewrite this to be &*self == C?

24–25
MaskRay added inline comments.May 23 2023, 3:29 PM
libcxxabi/src/demangle/StringViewExtras.h
24–25

Ah, *self == C looks good. It's a pity that front throws...

llvm/include/llvm/Demangle/StringViewExtras.h
32

size is more common than length.

philnik added inline comments.May 23 2023, 3:36 PM
libcxxabi/src/demangle/StringViewExtras.h
24–25

front() doesn't throw. All major implementation also mark it as noexcept as a conforming extension. It's just not required to be noexcept in case an implementation wants to throw in the UB case.

  • replace front() with *begin(), length() with size()
nickdesaulniers marked 3 inline comments as done.May 24 2023, 12:24 PM
MaskRay accepted this revision.May 24 2023, 1:37 PM
MaskRay added inline comments.
libcxxabi/src/demangle/StringViewExtras.h
30

if (needle.empty()) is a special case that can be handled by the generic code. It can be removed.

nickdesaulniers marked an inline comment as done.
  • remove special case for empty needle; it's already handled
ldionne accepted this revision.May 25 2023, 1:32 PM
This revision is now accepted and ready to land.May 25 2023, 1:32 PM
This revision was landed with ongoing or failed builds.May 25 2023, 2:35 PM
This revision was automatically updated to reflect the committed changes.