This is an archive of the discontinued LLVM Phabricator instance.

[demangler] Add StringView conversion operator
ClosedPublic

Authored by urnathan on Mar 4 2022, 5:14 AM.

Details

Summary

The OutputBuffer class tries to present a NUL-terminated string API to consumers. But several of them would prefer a StringView. In particular the Microsoft demangler, juggles between NUL-terminated and StringView, which is confusing.

This adds a StringView conversion, and adjusts the Demanglers that can benefit from that.

(For information, this is part of a series of demangler cleanups I have).

Diff Detail

Event Timeline

urnathan created this revision.Mar 4 2022, 5:14 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 4 2022, 5:14 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
urnathan requested review of this revision.Mar 4 2022, 5:14 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 4 2022, 5:14 AM
urnathan edited the summary of this revision. (Show Details)Mar 23 2022, 4:13 AM
urnathan added reviewers: erichkeane, dblaikie.

ping? It seems that at last it's got a good CI run without spurious fails.

dblaikie added inline comments.Mar 23 2022, 11:27 AM
llvm/lib/Demangle/MicrosoftDemangle.cpp
248–250

can this change be made independent of the rest of the patch? If so, it'd be good to separate it out.

973

Since the conversion operator is implicit, could the StringView() be omitted here?

2318–2319

I'd tend to recommend writing this as StringView B = OB if that's valid (since that syntax only allows implicit conversions - so it simplifies things for readers (they have to consider fewer possible conversion sequences))

urnathan updated this revision to Diff 417898.Mar 24 2022, 6:01 AM

Address comments, break out strcpy->memcpy change.

urnathan marked 3 inline comments as done.
urnathan added inline comments.
llvm/lib/Demangle/MicrosoftDemangle.cpp
973

indeed it can.

2318–2319

sure,

dblaikie accepted this revision.Mar 24 2022, 9:30 AM

Looks good (alternatively, to the suggested edits - I'd probably be OK with the conversion operator being explicit, then keeping all those explicit ctor/conversions - either way's roughly fine by me)

llvm/lib/Demangle/MicrosoftDemangle.cpp
1374–1375
1453
llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
124–125
llvm/unittests/Demangle/ItaniumDemangleTest.cpp
56–57
llvm/unittests/Demangle/OutputBufferTest.cpp
18–19
This revision is now accepted and ready to land.Mar 24 2022, 9:30 AM
urnathan updated this revision to Diff 418018.Mar 24 2022, 12:21 PM
urnathan marked 2 inline comments as done.

d'oh sometimes I can be so shortsighted. Fix all the cases you implied.

dblaikie accepted this revision.Mar 25 2022, 1:32 PM

d'oh sometimes I can be so shortsighted. Fix all the cases you implied.

No worries at all - I should've mentioned "this and other instances".

This revision was landed with ongoing or failed builds.Mar 28 2022, 11:20 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptMar 28 2022, 11:20 AM
Herald added a reviewer: Restricted Project. · View Herald Transcript