[lld] c4d9df9 - [lld-macho][nfc] Clean up a bunch of clang-tidy issues

Jez Ng via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 5 04:50:39 PDT 2023


Author: Jez Ng
Date: 2023-04-05T07:50:28-04:00
New Revision: c4d9df9f78f3109f6c3c7bafa6fc91162e8771b4

URL: https://github.com/llvm/llvm-project/commit/c4d9df9f78f3109f6c3c7bafa6fc91162e8771b4
DIFF: https://github.com/llvm/llvm-project/commit/c4d9df9f78f3109f6c3c7bafa6fc91162e8771b4.diff

LOG: [lld-macho][nfc] Clean up a bunch of clang-tidy issues

Added: 
    

Modified: 
    lld/MachO/ICF.cpp
    lld/MachO/InputFiles.cpp
    lld/MachO/SymbolTable.cpp
    lld/MachO/SyntheticSections.cpp
    lld/MachO/UnwindInfoSection.cpp
    lld/MachO/Writer.cpp

Removed: 
    


################################################################################
diff  --git a/lld/MachO/ICF.cpp b/lld/MachO/ICF.cpp
index 3dfc46412e842..d5f3c19c62785 100644
--- a/lld/MachO/ICF.cpp
+++ b/lld/MachO/ICF.cpp
@@ -213,8 +213,10 @@ bool ICF::equalsVariable(const ConcatInputSection *ia,
   // symbols at offset zero within the section (which is typically the case with
   // .subsections_via_symbols.)
   auto hasUnwind = [](Defined *d) { return d->unwindEntry != nullptr; };
-  auto itA = std::find_if(ia->symbols.begin(), ia->symbols.end(), hasUnwind);
-  auto itB = std::find_if(ib->symbols.begin(), ib->symbols.end(), hasUnwind);
+  const auto *itA =
+      std::find_if(ia->symbols.begin(), ia->symbols.end(), hasUnwind);
+  const auto *itB =
+      std::find_if(ib->symbols.begin(), ib->symbols.end(), hasUnwind);
   if (itA == ia->symbols.end())
     return itB == ib->symbols.end();
   if (itB == ib->symbols.end())
@@ -290,7 +292,7 @@ void ICF::run() {
         if (auto *sym = r.referent.dyn_cast<Symbol *>()) {
           if (auto *defined = dyn_cast<Defined>(sym)) {
             if (defined->isec) {
-              if (auto referentIsec =
+              if (auto *referentIsec =
                       dyn_cast<ConcatInputSection>(defined->isec))
                 hash += defined->value + referentIsec->icfEqClass[icfPass % 2];
               else

diff  --git a/lld/MachO/InputFiles.cpp b/lld/MachO/InputFiles.cpp
index 6edb21ffe672b..9f0c003d6aa2a 100644
--- a/lld/MachO/InputFiles.cpp
+++ b/lld/MachO/InputFiles.cpp
@@ -89,7 +89,7 @@ std::string lld::toString(const InputFile *f) {
     return "<internal>";
 
   // Multiple dylibs can be defined in one .tbd file.
-  if (auto dylibFile = dyn_cast<DylibFile>(f))
+  if (const auto *dylibFile = dyn_cast<DylibFile>(f))
     if (f->getName().endswith(".tbd"))
       return (f->getName() + "(" + dylibFile->installName + ")").str();
 
@@ -753,7 +753,7 @@ macho::Symbol *ObjFile::parseNonSectionSymbol(const NList &sym,
     StringRef aliasedName = StringRef(strtab + sym.n_value);
     // isPrivateExtern is the only symbol flag that has an impact on the final
     // aliased symbol.
-    auto alias = make<AliasSymbol>(this, name, aliasedName, isPrivateExtern);
+    auto *alias = make<AliasSymbol>(this, name, aliasedName, isPrivateExtern);
     aliases.push_back(alias);
     return alias;
   }
@@ -1597,8 +1597,8 @@ static DylibFile *findDylib(StringRef path, DylibFile *umbrella,
          make_pointee_range(currentTopLevelTapi->documents())) {
       assert(child.documents().empty());
       if (path == child.getInstallName()) {
-        auto file = make<DylibFile>(child, umbrella, /*isBundleLoader=*/false,
-                                    /*explicitlyLinked=*/false);
+        auto *file = make<DylibFile>(child, umbrella, /*isBundleLoader=*/false,
+                                     /*explicitlyLinked=*/false);
         file->parseReexports(child);
         return file;
       }
@@ -1692,14 +1692,15 @@ DylibFile::DylibFile(MemoryBufferRef mb, DylibFile *umbrella,
     error(toString(this) +
           ": dylib has both LC_DYLD_INFO_ONLY and LC_DYLD_EXPORTS_TRIE");
     return;
-  } else if (dyldInfo) {
+  }
+
+  if (dyldInfo) {
     parseExportedSymbols(dyldInfo->export_off, dyldInfo->export_size);
   } else if (exportsTrie) {
     parseExportedSymbols(exportsTrie->dataoff, exportsTrie->datasize);
   } else {
     error("No LC_DYLD_INFO_ONLY or LC_DYLD_EXPORTS_TRIE found in " +
           toString(this));
-    return;
   }
 }
 

diff  --git a/lld/MachO/SymbolTable.cpp b/lld/MachO/SymbolTable.cpp
index 09b3d8a376e60..78ac40bc52cec 100644
--- a/lld/MachO/SymbolTable.cpp
+++ b/lld/MachO/SymbolTable.cpp
@@ -459,8 +459,8 @@ static bool canSuggestExternCForCXX(StringRef ref, StringRef def) {
 // the suggested symbol, which is either in the symbol table, or in the same
 // file of sym.
 static const Symbol *getAlternativeSpelling(const Undefined &sym,
-                                            std::string &pre_hint,
-                                            std::string &post_hint) {
+                                            std::string &preHint,
+                                            std::string &postHint) {
   DenseMap<StringRef, const Symbol *> map;
   if (sym.getFile() && sym.getFile()->kind() == InputFile::ObjKind) {
     // Build a map of local defined symbols.
@@ -540,28 +540,28 @@ static const Symbol *getAlternativeSpelling(const Undefined &sym,
         const Symbol *s = suggest((Twine("_") + buf).str());
         free(buf);
         if (s) {
-          pre_hint = ": extern \"C\" ";
+          preHint = ": extern \"C\" ";
           return s;
         }
       }
   } else {
-    StringRef name_without_underscore = name;
-    name_without_underscore.consume_front("_");
+    StringRef nameWithoutUnderscore = name;
+    nameWithoutUnderscore.consume_front("_");
     const Symbol *s = nullptr;
     for (auto &it : map)
-      if (canSuggestExternCForCXX(name_without_underscore, it.first)) {
+      if (canSuggestExternCForCXX(nameWithoutUnderscore, it.first)) {
         s = it.second;
         break;
       }
     if (!s)
       for (Symbol *sym : symtab->getSymbols())
-        if (canSuggestExternCForCXX(name_without_underscore, sym->getName())) {
+        if (canSuggestExternCForCXX(nameWithoutUnderscore, sym->getName())) {
           s = sym;
           break;
         }
     if (s) {
-      pre_hint = " to declare ";
-      post_hint = " as extern \"C\"?";
+      preHint = " to declare ";
+      postHint = " as extern \"C\"?";
       return s;
     }
   }
@@ -605,11 +605,11 @@ static void reportUndefinedSymbol(const Undefined &sym,
             .str();
 
   if (correctSpelling) {
-    std::string pre_hint = ": ", post_hint;
+    std::string preHint = ": ", postHint;
     if (const Symbol *corrected =
-            getAlternativeSpelling(sym, pre_hint, post_hint)) {
+            getAlternativeSpelling(sym, preHint, postHint)) {
       message +=
-          "\n>>> did you mean" + pre_hint + toString(*corrected) + post_hint;
+          "\n>>> did you mean" + preHint + toString(*corrected) + postHint;
       if (corrected->getFile())
         message += "\n>>> defined in: " + toString(corrected->getFile());
     }

diff  --git a/lld/MachO/SyntheticSections.cpp b/lld/MachO/SyntheticSections.cpp
index 72ec67ad1e308..75453a5b3ee54 100644
--- a/lld/MachO/SyntheticSections.cpp
+++ b/lld/MachO/SyntheticSections.cpp
@@ -1875,7 +1875,7 @@ void ObjCImageInfoSection::finalizeContents() {
 
   info.hasCategoryClassProperties = true;
   const InputFile *firstFile;
-  for (auto file : files) {
+  for (const InputFile *file : files) {
     ImageInfo inputInfo = parseImageInfo(file);
     info.hasCategoryClassProperties &= inputInfo.hasCategoryClassProperties;
 

diff  --git a/lld/MachO/UnwindInfoSection.cpp b/lld/MachO/UnwindInfoSection.cpp
index 6820e177875ce..2dbd8ed202728 100644
--- a/lld/MachO/UnwindInfoSection.cpp
+++ b/lld/MachO/UnwindInfoSection.cpp
@@ -559,10 +559,10 @@ void UnwindInfoSectionImpl::finalize() {
     while (wordsRemaining >= 1 && i < cuIndices.size()) {
       idx = cuIndices[i];
       const CompactUnwindEntry *cuPtr = &cuEntries[idx];
-      if (cuPtr->functionAddress >= functionAddressMax) {
+      if (cuPtr->functionAddress >= functionAddressMax)
         break;
-      } else if (commonEncodingIndexes.count(cuPtr->encoding) ||
-                 page.localEncodingIndexes.count(cuPtr->encoding)) {
+      if (commonEncodingIndexes.count(cuPtr->encoding) ||
+          page.localEncodingIndexes.count(cuPtr->encoding)) {
         i++;
         wordsRemaining--;
       } else if (wordsRemaining >= 2 && n < COMPACT_ENCODINGS_MAX) {

diff  --git a/lld/MachO/Writer.cpp b/lld/MachO/Writer.cpp
index b090ca2a72b76..fe7cd39d2db88 100644
--- a/lld/MachO/Writer.cpp
+++ b/lld/MachO/Writer.cpp
@@ -1060,7 +1060,7 @@ void Writer::finalizeAddresses() {
       if (!osec->isNeeded())
         continue;
       // Other kinds of OutputSections have already been finalized.
-      if (auto concatOsec = dyn_cast<ConcatOutputSection>(osec))
+      if (auto *concatOsec = dyn_cast<ConcatOutputSection>(osec))
         concatOsec->finalizeContents();
     }
   }


        


More information about the llvm-commits mailing list