Skip to content

Commit

Permalink
[lld-macho][nfc][cleanup] Fix a few code style lints and clang-tidy f…
Browse files Browse the repository at this point in the history
…indings

- Use .empty() instead of `size() == 0` when possible.
- Use const-ref to avoid copying

Differential Revision: https://reviews.llvm.org/D112978
  • Loading branch information
oontvoo committed Nov 2, 2021
1 parent adf5e9c commit 3f35dd0
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lld/MachO/ConcatOutputSection.cpp
Expand Up @@ -353,7 +353,7 @@ void ConcatOutputSection::writeTo(uint8_t *buf) const {
size_t i = 0, ie = inputs.size();
size_t t = 0, te = thunks.size();
while (i < ie || t < te) {
while (i < ie && (t == te || inputs[i]->getSize() == 0 ||
while (i < ie && (t == te || inputs[i]->empty() ||
inputs[i]->outSecOff < thunks[t]->outSecOff)) {
inputs[i]->writeTo(buf + inputs[i]->outSecOff);
++i;
Expand Down
6 changes: 4 additions & 2 deletions lld/MachO/Driver.cpp
Expand Up @@ -174,7 +174,7 @@ static std::vector<StringRef> getSystemLibraryRoots(InputArgList &args) {
for (const Arg *arg : args.filtered(OPT_syslibroot))
roots.push_back(arg->getValue());
// NOTE: the final `-syslibroot` being `/` will ignore all roots
if (roots.size() && roots.back() == "/")
if (!roots.empty() && roots.back() == "/")
roots.clear();
// NOTE: roots can never be empty - add an empty root to simplify the library
// and framework search path computation.
Expand Down Expand Up @@ -206,7 +206,9 @@ static llvm::CachePruningPolicy getLTOCachePolicy(InputArgList &args) {
args.filtered(OPT_thinlto_cache_policy, OPT_prune_interval_lto,
OPT_prune_after_lto, OPT_max_relative_cache_size_lto)) {
switch (arg->getOption().getID()) {
case OPT_thinlto_cache_policy: add(arg->getValue()); break;
case OPT_thinlto_cache_policy:
add(arg->getValue());
break;
case OPT_prune_interval_lto:
if (!strcmp("-1", arg->getValue()))
add("prune_interval=87600h"); // 10 years
Expand Down
7 changes: 3 additions & 4 deletions lld/MachO/InputFiles.cpp
Expand Up @@ -269,7 +269,7 @@ void ObjFile::parseSections(ArrayRef<Section> sections) {

auto splitRecords = [&](int recordSize) -> void {
subsections.push_back({});
if (data.size() == 0)
if (data.empty())
return;

SubsectionMap &subsecMap = subsections.back();
Expand Down Expand Up @@ -619,8 +619,7 @@ macho::Symbol *ObjFile::parseNonSectionSymbol(const NList &sym,
}
}

template <class NList>
static bool isUndef(const NList &sym) {
template <class NList> static bool isUndef(const NList &sym) {
return (sym.n_type & N_TYPE) == N_UNDF && sym.n_value == 0;
}

Expand Down Expand Up @@ -1211,7 +1210,7 @@ DylibFile::DylibFile(const InterfaceFile &interface, DylibFile *umbrella,
void DylibFile::parseReexports(const InterfaceFile &interface) {
const InterfaceFile *topLevel =
interface.getParent() == nullptr ? &interface : interface.getParent();
for (InterfaceFileRef intfRef : interface.reexportedLibraries()) {
for (const InterfaceFileRef &intfRef : interface.reexportedLibraries()) {
InterfaceFile::const_target_range targets = intfRef.targets();
if (is_contained(skipPlatformChecks, intfRef.getInstallName()) ||
is_contained(targets, config->platformInfo.target))
Expand Down
2 changes: 1 addition & 1 deletion lld/MachO/InputSection.cpp
Expand Up @@ -110,7 +110,7 @@ void ConcatInputSection::foldIdentical(ConcatInputSection *copy) {
copy->symbols.clear();

// Remove duplicate compact unwind info for symbols at the same address.
if (symbols.size() == 0)
if (symbols.empty())
return;
it = symbols.begin();
uint64_t v = (*it)->value;
Expand Down
3 changes: 2 additions & 1 deletion lld/MachO/InputSection.h
Expand Up @@ -38,6 +38,7 @@ class InputSection {
Kind kind() const { return shared->sectionKind; }
virtual ~InputSection() = default;
virtual uint64_t getSize() const { return data.size(); }
virtual bool empty() const { return data.empty(); }
InputFile *getFile() const { return shared->file; }
StringRef getName() const { return shared->name; }
StringRef getSegName() const { return shared->segname; }
Expand Down Expand Up @@ -115,7 +116,7 @@ class ConcatInputSection final : public InputSection {
// ConcatInputSections are entirely live or dead, so the offset is irrelevant.
bool isLive(uint64_t off) const override { return live; }
void markLive(uint64_t off) override { live = true; }
bool isCoalescedWeak() const { return wasCoalesced && symbols.size() == 0; }
bool isCoalescedWeak() const { return wasCoalesced && symbols.empty(); }
bool shouldOmitFromOutput() const { return !live || isCoalescedWeak(); }
bool isHashableForICF() const;
void hashForICF();
Expand Down
2 changes: 1 addition & 1 deletion lld/MachO/UnwindInfoSection.cpp
Expand Up @@ -602,7 +602,7 @@ void UnwindInfoSectionImpl<Ptr>::writeTo(uint8_t *buf) const {
*ep++ = (it->second << COMPRESSED_ENTRY_FUNC_OFFSET_BITS) |
(cuep->functionAddress - functionAddressBase);
}
if (page.localEncodings.size() != 0)
if (!page.localEncodings.empty())
memcpy(ep, page.localEncodings.data(),
page.localEncodings.size() * sizeof(uint32_t));
} else {
Expand Down

0 comments on commit 3f35dd0

Please sign in to comment.