This is an archive of the discontinued LLVM Phabricator instance.

ADT: Use 'using' to inherit assign and append in SmallString
ClosedPublic

Authored by dexonsmith on Jan 21 2021, 9:17 PM.

Details

Summary

Rather than reimplement, use a using declaration to bring in
SmallVectorImpl<char>'s assign and append implementations in
SmallString.

The SmallString versions were missing reference invalidation
assertions from SmallVector. This patch also fixes a bug in
llvm::FileCollector::addFileImpl, which was a copy/paste from
clang::ModuleDependencyCollector::copyToRoot, both caught by the
no-longer-skipped assertions.

As a drive-by, this also sinks the const SmallVectorImpl& versions of
these methods down into SmallVectorImpl, since I imagine they'd be
useful elsewhere.

Diff Detail

Event Timeline

dexonsmith created this revision.Jan 21 2021, 9:17 PM
dexonsmith requested review of this revision.Jan 21 2021, 9:17 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptJan 21 2021, 9:17 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
dblaikie accepted this revision.Jan 22 2021, 1:37 PM

Looks good - some optional feedback on the code fixes. Please run clang-format on the changes here (phab lint picked up some cases in the test code that could be cleaned up).

clang/lib/Frontend/ModuleDependencyCollector.cpp
196

Maybe just call this inconditionally - it's probably cheap enough when the range is zero-length?

Perhaps it'd be more readable if "remove_leading_dotslash" had a version that could return the prefix length to remove.

But also, this is ultimately passed to 'getRealPath' which takes a StringRef, so there's technically no need to rewrite this SmallString - the StringRef from remove_leading_dotslash could be passed instead, something like:

StringRef TrimmedAbsoluteSrc = path::remove_leading_dotslash(AbsoluteSrc);
...
if (!getRealPath(AbsoluteSrc, CopyFrom))
...
llvm/lib/Support/FileCollector.cpp
89–91

Similar comment here as with ModuleDependencyCollector (actually there's a bunch of similar code here - perhaps it could be deduplicated in some way)

This revision is now accepted and ready to land.Jan 22 2021, 1:37 PM
This revision was landed with ongoing or failed builds.Jan 22 2021, 4:18 PM
This revision was automatically updated to reflect the committed changes.
dexonsmith marked 2 inline comments as done.Jan 22 2021, 4:42 PM

Thanks for the review! Pushed with suggestions applied in ba5628f2c2a9de049b80b3e276f7e05f481c49e7.

llvm/lib/Support/FileCollector.cpp
89–91

Yeah, I may follow up to fix that. It looks like a pure copy/paste...