diff --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp --- a/lld/MachO/Driver.cpp +++ b/lld/MachO/Driver.cpp @@ -164,8 +164,8 @@ if (args.hasArg(OPT_Z)) return paths; - for (auto const &path : systemPaths) { - for (auto root : roots) { + for (const StringRef &path : systemPaths) { + for (const StringRef &root : roots) { SmallString<261> buffer(root); path::append(buffer, path); if (fs::is_directory(buffer)) @@ -252,7 +252,7 @@ MemoryBufferRef mbref = *buffer; InputFile *newFile = nullptr; - auto magic = identify_magic(mbref.getBuffer()); + file_magic magic = identify_magic(mbref.getBuffer()); switch (magic) { case file_magic::archive: { std::unique_ptr file = CHECK( @@ -368,10 +368,10 @@ opt::InputArgList args = table.ParseArgs(argv, missingIndex, missingCount); if (missingCount) fatal(Twine(args.getArgString(missingIndex)) + ": missing argument"); - for (auto *arg : args.filtered(OPT_UNKNOWN)) + for (const Arg *arg : args.filtered(OPT_UNKNOWN)) error("unknown argument: " + arg->getAsString(args)); - for (auto *arg : args) { + for (const Arg *arg : args) { switch (arg->getOption().getID()) { case OPT_l: addLibrary(arg->getValue(), false); @@ -493,7 +493,7 @@ } static void compileBitcodeFiles() { - auto lto = make(); + auto *lto = make(); for (InputFile *file : inputFiles) if (auto *bitcodeFile = dyn_cast(file)) lto->add(*bitcodeFile); @@ -663,7 +663,7 @@ } static const char *getReproduceOption(opt::InputArgList &args) { - if (auto *arg = args.getLastArg(OPT_reproduce)) + if (const Arg *arg = args.getLastArg(OPT_reproduce)) return arg->getValue(); return getenv("LLD_REPRODUCE"); } @@ -752,9 +752,9 @@ SymbolPatterns &symbolPatterns, unsigned singleOptionCode, unsigned listFileOptionCode) { - for (opt::Arg *arg : args.filtered(singleOptionCode)) + for (const Arg *arg : args.filtered(singleOptionCode)) symbolPatterns.insert(arg->getValue()); - for (opt::Arg *arg : args.filtered(listFileOptionCode)) { + for (const Arg *arg : args.filtered(listFileOptionCode)) { StringRef path = arg->getValue(); Optional buffer = readFile(path); if (!buffer) { @@ -819,12 +819,12 @@ config->entry = symtab->addUndefined(args.getLastArgValue(OPT_e, "_main"), /*file=*/nullptr, /*isWeakRef=*/false); - for (auto *arg : args.filtered(OPT_u)) { + for (const Arg *arg : args.filtered(OPT_u)) { config->explicitUndefineds.push_back(symtab->addUndefined( arg->getValue(), /*file=*/nullptr, /*isWeakRef=*/false)); } - for (auto *arg : args.filtered(OPT_U)) + for (const Arg *arg : args.filtered(OPT_U)) symtab->addDynamicLookup(arg->getValue()); config->outputFile = args.getLastArgValue(OPT_o, "a.out"); @@ -884,12 +884,12 @@ error("invalid name for segment or section: " + s); return s; }; - for (opt::Arg *arg : args.filtered(OPT_rename_section)) { + for (const Arg *arg : args.filtered(OPT_rename_section)) { config->sectionRenameMap[{validName(arg->getValue(0)), validName(arg->getValue(1))}] = { validName(arg->getValue(2)), validName(arg->getValue(3))}; } - for (opt::Arg *arg : args.filtered(OPT_rename_segment)) { + for (const Arg *arg : args.filtered(OPT_rename_segment)) { config->segmentRenameMap[validName(arg->getValue(0))] = validName(arg->getValue(1)); } @@ -926,8 +926,8 @@ // This loop should be reserved for options whose exact ordering matters. // Other options should be handled via filtered() and/or getLastArg(). - for (const auto &arg : args) { - const auto &opt = arg->getOption(); + for (const Arg *arg : args) { + const Option &opt = arg->getOption(); warnIfDeprecatedOption(opt); warnIfUnimplementedOption(opt); @@ -964,7 +964,7 @@ // Now that all dylibs have been loaded, search for those that should be // re-exported. - for (opt::Arg *arg : args.filtered(OPT_sub_library, OPT_sub_umbrella)) { + for (const Arg *arg : args.filtered(OPT_sub_library, OPT_sub_umbrella)) { config->hasReexports = true; StringRef searchName = arg->getValue(); std::vector extensions; @@ -978,11 +978,11 @@ } // Parse LTO options. - if (auto *arg = args.getLastArg(OPT_mcpu)) + if (const Arg *arg = args.getLastArg(OPT_mcpu)) parseClangOption(saver.save("-mcpu=" + StringRef(arg->getValue())), arg->getSpelling()); - for (auto *arg : args.filtered(OPT_mllvm)) + for (const Arg *arg : args.filtered(OPT_mllvm)) parseClangOption(arg->getValue(), arg->getSpelling()); compileBitcodeFiles(); @@ -998,7 +998,7 @@ } // FIXME: This prints symbols that are undefined both in input files and // via -u flag twice. - for (const auto *undefined : config->explicitUndefineds) { + for (const Symbol *undefined : config->explicitUndefineds) { if (isa(undefined)) { error("undefined symbol: " + toString(*undefined) + "\n>>> referenced by flag -u " + toString(*undefined)); @@ -1009,7 +1009,7 @@ createSyntheticSections(); symtab->addDSOHandle(in.header); - for (opt::Arg *arg : args.filtered(OPT_sectcreate)) { + for (const Arg *arg : args.filtered(OPT_sectcreate)) { StringRef segName = arg->getValue(0); StringRef sectName = arg->getValue(1); StringRef fileName = arg->getValue(2); @@ -1021,7 +1021,7 @@ // Initialize InputSections. for (InputFile *file : inputFiles) { for (SubsectionMap &map : file->subsections) { - for (auto &p : map) { + for (const auto &p : map) { InputSection *isec = p.second; inputSections.push_back(isec); } diff --git a/lld/MachO/DriverUtils.cpp b/lld/MachO/DriverUtils.cpp --- a/lld/MachO/DriverUtils.cpp +++ b/lld/MachO/DriverUtils.cpp @@ -52,8 +52,9 @@ // Set color diagnostics according to --color-diagnostics={auto,always,never} // or --no-color-diagnostics flags. static void handleColorDiagnostics(opt::InputArgList &args) { - auto *arg = args.getLastArg(OPT_color_diagnostics, OPT_color_diagnostics_eq, - OPT_no_color_diagnostics); + const Arg *arg = + args.getLastArg(OPT_color_diagnostics, OPT_color_diagnostics_eq, + OPT_no_color_diagnostics); if (!arg) return; if (arg->getOption().getID() == OPT_color_diagnostics) { @@ -121,7 +122,7 @@ raw_svector_ostream os(data); // Copy the command line to the output while rewriting paths. - for (auto *arg : args) { + for (const Arg *arg : args) { switch (arg->getOption().getID()) { case OPT_reproduce: break; diff --git a/lld/MachO/InputFiles.cpp b/lld/MachO/InputFiles.cpp --- a/lld/MachO/InputFiles.cpp +++ b/lld/MachO/InputFiles.cpp @@ -99,8 +99,8 @@ // Open a given file path and return it as a memory-mapped file. Optional macho::readFile(StringRef path) { // Open a file. - auto mbOrErr = MemoryBuffer::getFile(path); - if (auto ec = mbOrErr.getError()) { + ErrorOr> mbOrErr = MemoryBuffer::getFile(path); + if (std::error_code ec = mbOrErr.getError()) { error("cannot open " + path + ": " + ec.message()); return None; } @@ -749,7 +749,7 @@ }; // TODO(compnerd) filter out symbols based on the target platform // TODO: handle weak defs, thread locals - for (const auto symbol : interface.symbols()) { + for (const auto *symbol : interface.symbols()) { if (!symbol->getArchitectures().has(config->target.Arch)) continue; @@ -776,7 +776,7 @@ interface.getParent() == nullptr ? &interface : interface.getParent(); for (InterfaceFileRef intfRef : interface.reexportedLibraries()) { - auto targets = intfRef.targets(); + InterfaceFile::const_target_range targets = intfRef.targets(); if (is_contained(targets, config->target)) loadReexport(intfRef.getInstallName(), exportingFile, topLevel); } diff --git a/lld/MachO/InputSection.cpp b/lld/MachO/InputSection.cpp --- a/lld/MachO/InputSection.cpp +++ b/lld/MachO/InputSection.cpp @@ -58,14 +58,15 @@ memcpy(buf, data.data(), data.size()); for (size_t i = 0; i < relocs.size(); i++) { - auto *fromSym = target->hasAttr(relocs[i].type, RelocAttrBits::SUBTRAHEND) - ? relocs[i++].referent.get() - : nullptr; + const Symbol *fromSym = + target->hasAttr(relocs[i].type, RelocAttrBits::SUBTRAHEND) + ? relocs[i++].referent.get() + : nullptr; const Reloc &r = relocs[i]; uint8_t *loc = buf + r.offset; uint64_t referentVA = 0; if (fromSym) { - auto *toSym = r.referent.get(); + const Symbol *toSym = r.referent.get(); referentVA = toSym->getVA() - fromSym->getVA(); } else if (auto *referentSym = r.referent.dyn_cast()) { if (target->hasAttr(r.type, RelocAttrBits::LOAD) && diff --git a/lld/MachO/LTO.cpp b/lld/MachO/LTO.cpp --- a/lld/MachO/LTO.cpp +++ b/lld/MachO/LTO.cpp @@ -40,7 +40,7 @@ } BitcodeCompiler::BitcodeCompiler() { - auto backend = + lto::ThinBackend backend = lto::createInProcessThinBackend(heavyweight_hardware_concurrency()); ltoObj = std::make_unique(createConfig(), backend); } diff --git a/lld/MachO/SymbolTable.cpp b/lld/MachO/SymbolTable.cpp --- a/lld/MachO/SymbolTable.cpp +++ b/lld/MachO/SymbolTable.cpp @@ -79,7 +79,7 @@ bool wasInserted; std::tie(s, wasInserted) = insert(name); - auto refState = isWeakRef ? RefState::Weak : RefState::Strong; + RefState refState = isWeakRef ? RefState::Weak : RefState::Strong; if (wasInserted) replaceSymbol(s, name, file, refState); @@ -119,7 +119,7 @@ bool wasInserted; std::tie(s, wasInserted) = insert(name); - auto refState = RefState::Unreferenced; + RefState refState = RefState::Unreferenced; if (!wasInserted) { if (auto *defined = dyn_cast(s)) { if (isWeakDef && !defined->isWeakDef()) diff --git a/lld/MachO/SyntheticSections.cpp b/lld/MachO/SyntheticSections.cpp --- a/lld/MachO/SyntheticSections.cpp +++ b/lld/MachO/SyntheticSections.cpp @@ -372,11 +372,11 @@ return a.target.getVA() < b.target.getVA(); }); for (const WeakBindingEntry &b : bindings) { - if (auto *isec = b.target.section.dyn_cast()) { + if (const auto *isec = b.target.section.dyn_cast()) { encodeBinding(b.symbol, isec->parent, isec->outSecOff + b.target.offset, b.addend, /*isWeakBinding=*/true, lastBinding, os); } else { - auto *osec = b.target.section.get(); + const auto *osec = b.target.section.get(); encodeBinding(b.symbol, osec, b.target.offset, b.addend, /*isWeakBinding=*/true, lastBinding, os); } diff --git a/lld/MachO/UnwindInfoSection.cpp b/lld/MachO/UnwindInfoSection.cpp --- a/lld/MachO/UnwindInfoSection.cpp +++ b/lld/MachO/UnwindInfoSection.cpp @@ -280,7 +280,7 @@ // Count frequencies of the folded encodings EncodingMap encodingFrequencies; - for (auto cuPtrEntry : cuPtrVector) + for (const CompactUnwindEntry64 *cuPtrEntry : cuPtrVector) encodingFrequencies[cuPtrEntry->encoding]++; // Make a vector of encodings, sorted by descending frequency @@ -316,7 +316,7 @@ // If more entries fit in the regular format, we use that. for (size_t i = 0; i < cuPtrVector.size();) { secondLevelPages.emplace_back(); - auto &page = secondLevelPages.back(); + UnwindInfoSection::SecondLevelPage &page = secondLevelPages.back(); page.entryIndex = i; uintptr_t functionAddressMax = cuPtrVector[i]->functionAddress + COMPRESSED_ENTRY_FUNC_OFFSET_MASK; @@ -326,7 +326,7 @@ sizeof(unwind_info_compressed_second_level_page_header) / sizeof(uint32_t); while (wordsRemaining >= 1 && i < cuPtrVector.size()) { - const auto *cuPtr = cuPtrVector[i]; + const CompactUnwindEntry64 *cuPtr = cuPtrVector[i]; if (cuPtr->functionAddress >= functionAddressMax) { break; } else if (commonEncodingIndexes.count(cuPtr->encoding) ||