[lld] 3f35dd0 - [lld-macho][nfc][cleanup] Fix a few code style lints and clang-tidy findings
Vy Nguyen via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 2 08:35:56 PDT 2021
Author: Vy Nguyen
Date: 2021-11-02T11:26:15-04:00
New Revision: 3f35dd06a5be17e9ed5ecfefcc21394e4443c31e
URL: https://github.com/llvm/llvm-project/commit/3f35dd06a5be17e9ed5ecfefcc21394e4443c31e
DIFF: https://github.com/llvm/llvm-project/commit/3f35dd06a5be17e9ed5ecfefcc21394e4443c31e.diff
LOG: [lld-macho][nfc][cleanup] Fix a few code style lints and clang-tidy findings
- Use .empty() instead of `size() == 0` when possible.
- Use const-ref to avoid copying
Differential Revision: https://reviews.llvm.org/D112978
Added:
Modified:
lld/MachO/ConcatOutputSection.cpp
lld/MachO/Driver.cpp
lld/MachO/InputFiles.cpp
lld/MachO/InputSection.cpp
lld/MachO/InputSection.h
lld/MachO/UnwindInfoSection.cpp
Removed:
################################################################################
diff --git a/lld/MachO/ConcatOutputSection.cpp b/lld/MachO/ConcatOutputSection.cpp
index 5ab49f77b150a..17da4d045585d 100644
--- a/lld/MachO/ConcatOutputSection.cpp
+++ b/lld/MachO/ConcatOutputSection.cpp
@@ -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;
diff --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp
index 528e78055728d..9ecc05e1c8d2f 100644
--- a/lld/MachO/Driver.cpp
+++ b/lld/MachO/Driver.cpp
@@ -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.
@@ -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
diff --git a/lld/MachO/InputFiles.cpp b/lld/MachO/InputFiles.cpp
index 1f4313dd296f5..d406920620f6f 100644
--- a/lld/MachO/InputFiles.cpp
+++ b/lld/MachO/InputFiles.cpp
@@ -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();
@@ -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;
}
@@ -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))
diff --git a/lld/MachO/InputSection.cpp b/lld/MachO/InputSection.cpp
index 879f7da1c45c5..ebb4d204d9acc 100644
--- a/lld/MachO/InputSection.cpp
+++ b/lld/MachO/InputSection.cpp
@@ -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;
diff --git a/lld/MachO/InputSection.h b/lld/MachO/InputSection.h
index 85036135570aa..621cea5073b9b 100644
--- a/lld/MachO/InputSection.h
+++ b/lld/MachO/InputSection.h
@@ -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; }
@@ -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();
diff --git a/lld/MachO/UnwindInfoSection.cpp b/lld/MachO/UnwindInfoSection.cpp
index dca537493de49..f3f7fdbcd0f41 100644
--- a/lld/MachO/UnwindInfoSection.cpp
+++ b/lld/MachO/UnwindInfoSection.cpp
@@ -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 {
More information about the llvm-commits
mailing list