This is an archive of the discontinued LLVM Phabricator instance.

[Demangle] make llvm::demangle take a StringRef; NFC
AbandonedPublic

Authored by nickdesaulniers on Apr 12 2023, 4:05 PM.

Details

Reviewers
erichkeane
MaskRay
jhenderson
Group Reviewers
Restricted Project

Diff Detail

Event Timeline

Herald added projects: Restricted Project, Restricted Project. · View Herald Transcript
Herald added a reviewer: Restricted Project. · View Herald Transcript
nickdesaulniers requested review of this revision.Apr 12 2023, 4:05 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptApr 12 2023, 4:05 PM

There's a few more callsites I'd like to clean up, tomorrow:

  • llvm/tools/llvm-objdump/llvm-objdump.cpp
  • llvm/tools/llvm-objdump/XCOFFDump.cpp
sbc100 added inline comments.Apr 12 2023, 4:08 PM
llvm/lib/Demangle/Demangle.cpp
29

Should const be removed? (i.e. is StringRef not inherently const?)

Unfortunately we cannot do this. LLVMSupport depends on LLVMDemangle. Due to library layering LLVMDemangle cannot depend on LLVMSupport.
The layering may look weird, but that's what we have.

Using std::string_view may possibly be fine.

We're C++17 compilation now, so we should be able to use std::string_view (and I think we're supposed to?).

llvm/lib/Demangle/Demangle.cpp
31

std::string is implicitly constructible from a std::string_view, so I think on line 37 we can just do: MangledName[0] instead of S[0], and just do return MangledName below, rather than constructing it every time, despite it being just destructed in every other branch.

Though, I guess the 'gotcha' here is that despite everything else not modifying the S here, that we're no longer able to use strlen for the length. Perhaps this change should be more viral, in that the other demangle functions should take a string_view instead of a const char * as well.

llvm/lib/Demangle/Demangle.cpp
31

Perhaps this change should be more viral, in that the other demangle functions should take a string_view instead of a const char * as well.

Sigh, include/llvm/Demangle/StringView.h has a comment

9 // FIXME: Use std::string_view instead when we support C++17.

and is used throughout llvm/lib/Demangle/. This is potentially a large cleanup. Let me start on that...

llvm/lib/Demangle/Demangle.cpp
31

Not having starts_with and ends_with until C++20 is going to be a PITA.

erichkeane added inline comments.Apr 13 2023, 11:37 AM
llvm/lib/Demangle/Demangle.cpp
31

Ouch, yeah, i could see that being a problem. Perhaps we need an llvm::starts_with/llvm::ends_with that implements in terms of substr?

llvm/lib/Demangle/Demangle.cpp
31

Yeah, I guess llvm/ADT/STLExtras.h might be an appropriate place to add them.

So far in the conversion, another pain point has been llvm::StringView's constructor that takes two char*'s. I think to break up this conversion, I might remove that constructor and modify the callsites.

nickdesaulniers abandoned this revision.Apr 14 2023, 9:53 AM

Just going to rip out llvm::StringView.