Index: llvm/include/llvm/MC/MCParser/MCAsmParser.h =================================================================== --- llvm/include/llvm/MC/MCParser/MCAsmParser.h +++ llvm/include/llvm/MC/MCParser/MCAsmParser.h @@ -237,7 +237,7 @@ bool printPendingErrors() { bool rv = !PendingErrors.empty(); - for (auto Err : PendingErrors) { + for (const auto &Err : PendingErrors) { printError(Err.Loc, Twine(Err.Msg), Err.Range); } PendingErrors.clear(); Index: llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp =================================================================== --- llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp +++ llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp @@ -303,7 +303,7 @@ if (Abbrev) { const DWARFAbbreviationDeclarationSet *AbbrDecls = Abbrev->getAbbreviationDeclarationSet(0); - for (auto AbbrDecl : *AbbrDecls) { + for (const auto &AbbrDecl : *AbbrDecls) { SmallDenseSet AttributeSet; for (auto Attribute : AbbrDecl.attributes()) { auto Result = AttributeSet.insert(Attribute.Attr); @@ -412,10 +412,11 @@ uint64_t Sig = E.getSignature(); if (!E.getContributions()) continue; - for (auto E : enumerate(InfoColumnKind == DW_SECT_INFO - ? makeArrayRef(E.getContributions(), - Index.getColumnKinds().size()) - : makeArrayRef(E.getContribution(), 1))) { + for (const auto &E : + enumerate(InfoColumnKind == DW_SECT_INFO + ? makeArrayRef(E.getContributions(), + Index.getColumnKinds().size()) + : makeArrayRef(E.getContribution(), 1))) { const DWARFUnitIndex::Entry::SectionContribution &SC = E.value(); int Col = E.index(); if (SC.Length == 0) Index: llvm/lib/MC/ELFObjectWriter.cpp =================================================================== --- llvm/lib/MC/ELFObjectWriter.cpp +++ llvm/lib/MC/ELFObjectWriter.cpp @@ -656,7 +656,7 @@ // Add the data for the symbols. bool HasLargeSectionIndex = false; - for (auto It : llvm::enumerate(Asm.symbols())) { + for (const auto &It : llvm::enumerate(Asm.symbols())) { const auto &Symbol = cast(It.value()); bool Used = Symbol.isUsedInReloc(); bool WeakrefUsed = Symbol.isWeakrefUsedInReloc(); Index: llvm/lib/MC/MCPseudoProbe.cpp =================================================================== --- llvm/lib/MC/MCPseudoProbe.cpp +++ llvm/lib/MC/MCPseudoProbe.cpp @@ -545,7 +545,7 @@ void MCPseudoProbeDecoder::printProbesForAllAddresses(raw_ostream &OS) { std::vector Addresses; - for (auto Entry : Address2ProbesMap) + for (const auto &Entry : Address2ProbesMap) Addresses.push_back(Entry.first); llvm::sort(Addresses); for (auto K : Addresses) { Index: llvm/lib/ObjCopy/ELF/ELFObject.cpp =================================================================== --- llvm/lib/ObjCopy/ELF/ELFObject.cpp +++ llvm/lib/ObjCopy/ELF/ELFObject.cpp @@ -2070,7 +2070,7 @@ Size); } - for (auto it : Obj.getUpdatedSections()) { + for (const auto &it : Obj.getUpdatedSections()) { SectionBase *Sec = it.first; ArrayRef Data = it.second; Index: llvm/lib/Object/COFFImportFile.cpp =================================================================== --- llvm/lib/Object/COFFImportFile.cpp +++ llvm/lib/Object/COFFImportFile.cpp @@ -590,7 +590,7 @@ std::vector NullThunk; Members.push_back(OF.createNullThunk(NullThunk)); - for (COFFShortExport E : Exports) { + for (const COFFShortExport &E : Exports) { if (E.Private) continue; Index: llvm/lib/ObjectYAML/MachOEmitter.cpp =================================================================== --- llvm/lib/ObjectYAML/MachOEmitter.cpp +++ llvm/lib/ObjectYAML/MachOEmitter.cpp @@ -420,7 +420,7 @@ void MachOWriter::writeBindOpcodes( raw_ostream &OS, std::vector &BindOpcodes) { - for (auto Opcode : BindOpcodes) { + for (const auto &Opcode : BindOpcodes) { uint8_t OpByte = Opcode.Opcode | Opcode.Imm; OS.write(reinterpret_cast(&OpByte), 1); for (auto Data : Opcode.ULEBExtraData) { @@ -452,7 +452,7 @@ } } OS.write(static_cast(Entry.Children.size())); - for (auto EE : Entry.Children) { + for (const auto &EE : Entry.Children) { OS << EE.Name; OS.write('\0'); encodeULEB128(EE.NodeOffset, OS); @@ -553,7 +553,7 @@ void MachOWriter::writeRebaseOpcodes(raw_ostream &OS) { MachOYAML::LinkEditData &LinkEdit = Obj.LinkEdit; - for (auto Opcode : LinkEdit.RebaseOpcodes) { + for (const auto &Opcode : LinkEdit.RebaseOpcodes) { uint8_t OpByte = Opcode.Opcode | Opcode.Imm; OS.write(reinterpret_cast(&OpByte), 1); for (auto Data : Opcode.ExtraData) Index: llvm/lib/ObjectYAML/WasmEmitter.cpp =================================================================== --- llvm/lib/ObjectYAML/WasmEmitter.cpp +++ llvm/lib/ObjectYAML/WasmEmitter.cpp @@ -193,7 +193,7 @@ if (Section.SymbolTable.size()) { writeUint8(OS, wasm::WASM_SYMBOL_TABLE); encodeULEB128(Section.SymbolTable.size(), SubSection.getStream()); - for (auto Sym : llvm::enumerate(Section.SymbolTable)) { + for (const auto &Sym : llvm::enumerate(Section.SymbolTable)) { const WasmYAML::SymbolInfo &Info = Sym.value(); assert(Info.Index == Sym.index()); writeUint8(SubSection.getStream(), Info.Kind); Index: llvm/lib/Support/VirtualFileSystem.cpp =================================================================== --- llvm/lib/Support/VirtualFileSystem.cpp +++ llvm/lib/Support/VirtualFileSystem.cpp @@ -488,7 +488,7 @@ if (Type == PrintType::Contents) Type = PrintType::Summary; - for (auto FS : overlays_range()) + for (const auto &FS : overlays_range()) FS->print(OS, Type, IndentLevel + 1); } @@ -551,7 +551,7 @@ public: CombiningDirIterImpl(ArrayRef FileSystems, std::string Dir, std::error_code &EC) { - for (auto FS : FileSystems) { + for (const auto &FS : FileSystems) { std::error_code FEC; directory_iterator Iter = FS->dir_begin(Dir, FEC); if (FEC && FEC != errc::no_such_file_or_directory) { Index: llvm/lib/TextAPI/TextStub.cpp =================================================================== --- llvm/lib/TextAPI/TextStub.cpp +++ llvm/lib/TextAPI/TextStub.cpp @@ -1139,7 +1139,7 @@ std::vector Files; Files.emplace_back(&File); - for (auto Document : File.documents()) + for (const auto &Document : File.documents()) Files.emplace_back(Document.get()); // Stream out yaml. Index: llvm/tools/dsymutil/BinaryHolder.cpp =================================================================== --- llvm/tools/dsymutil/BinaryHolder.cpp +++ llvm/tools/dsymutil/BinaryHolder.cpp @@ -182,7 +182,7 @@ for (const auto &Archive : Archives) { Error Err = Error::success(); - for (auto Child : Archive->children(Err)) { + for (const auto &Child : Archive->children(Err)) { if (auto NameOrErr = Child.getName()) { if (*NameOrErr == ObjectFilename) { auto ModTimeOrErr = Child.getLastModified(); Index: llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp =================================================================== --- llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp +++ llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp @@ -321,7 +321,7 @@ return true; if (auto *MachO = dyn_cast(&Obj)) { - for (auto Arch : ArchFilters) { + for (const auto &Arch : ArchFilters) { // Match architecture number. unsigned Value; if (!StringRef(Arch).getAsInteger(0, Value)) @@ -566,7 +566,7 @@ // Handle the --name option. if (!Name.empty()) { StringSet<> Names; - for (auto name : Name) + for (const auto &name : Name) Names.insert((IgnoreCase && !UseRegex) ? StringRef(name).lower() : name); filterByName(Names, DICtx.normal_units(), OS); @@ -607,7 +607,7 @@ HandlerFn HandleObj, raw_ostream &OS) { bool Result = true; Error Err = Error::success(); - for (auto Child : Arch.children(Err)) { + for (const auto &Child : Arch.children(Err)) { auto BuffOrErr = Child.getMemoryBufferRef(); error(Filename, BuffOrErr.takeError()); auto NameOrErr = Child.getName(); @@ -756,19 +756,19 @@ bool Success = true; if (Verify) { - for (auto Object : Objects) + for (const auto &Object : Objects) Success &= handleFile(Object, verifyObjectFile, OutputFile.os()); } else if (Statistics) { - for (auto Object : Objects) + for (const auto &Object : Objects) Success &= handleFile(Object, collectStatsForObjectFile, OutputFile.os()); } else if (ShowSectionSizes) { - for (auto Object : Objects) + for (const auto &Object : Objects) Success &= handleFile(Object, collectObjectSectionSizes, OutputFile.os()); } else if (ShowSources) { - for (auto Object : Objects) + for (const auto &Object : Objects) Success &= handleFile(Object, collectObjectSources, OutputFile.os()); } else { - for (auto Object : Objects) + for (const auto &Object : Objects) Success &= handleFile(Object, dumpObjectFile, OutputFile.os()); } Index: llvm/tools/llvm-gsymutil/llvm-gsymutil.cpp =================================================================== --- llvm/tools/llvm-gsymutil/llvm-gsymutil.cpp +++ llvm/tools/llvm-gsymutil/llvm-gsymutil.cpp @@ -162,7 +162,7 @@ Triple ObjTriple(Obj.getArchTriple()); StringRef ObjArch = ObjTriple.getArchName(); - for (auto Arch : ArchFilters) { + for (const auto &Arch : ArchFilters) { // Match name. if (Arch == ObjArch) return true; @@ -403,7 +403,7 @@ error(DsymObjectsOrErr.takeError()); } - for (auto Object : Objects) { + for (const auto &Object : Objects) { if (auto Err = handleFileConversionToGSYM(Object, OutFile)) return Err; } Index: llvm/tools/llvm-pdbutil/TypeReferenceTracker.cpp =================================================================== --- llvm/tools/llvm-pdbutil/TypeReferenceTracker.cpp +++ llvm/tools/llvm-pdbutil/TypeReferenceTracker.cpp @@ -55,7 +55,7 @@ // - globals // - modi symbols // - LF_UDT_MOD_SRC_LINE? VC always links these in. - for (SymbolGroup SG : File.symbol_groups()) { + for (const SymbolGroup &SG : File.symbol_groups()) { if (File.isObj()) { for (const auto &SS : SG.getDebugSubsections()) { // FIXME: Are there other type-referencing subsections? Inlinees? Index: llvm/tools/llvm-pdbutil/llvm-pdbutil.cpp =================================================================== --- llvm/tools/llvm-pdbutil/llvm-pdbutil.cpp +++ llvm/tools/llvm-pdbutil/llvm-pdbutil.cpp @@ -842,7 +842,7 @@ ExitOnErr(DbiBuilder.addModuleSourceFile(ModiBuilder, S)); if (MI.Modi) { const auto &ModiStream = *MI.Modi; - for (auto Symbol : ModiStream.Symbols) { + for (const auto &Symbol : ModiStream.Symbols) { ModiBuilder.addSymbol( Symbol.toCodeViewSymbol(Allocator, CodeViewContainer::Pdb)); } Index: llvm/tools/llvm-readobj/ObjDumper.h =================================================================== --- llvm/tools/llvm-readobj/ObjDumper.h +++ llvm/tools/llvm-readobj/ObjDumper.h @@ -52,7 +52,7 @@ void addPredicate(CompPredicate Pred) { Predicates.push_back(Pred); } bool operator()(object::SymbolRef LHS, object::SymbolRef RHS) { - for (CompPredicate Pred : Predicates) { + for (const CompPredicate &Pred : Predicates) { if (Pred(LHS, RHS)) return true; if (Pred(RHS, LHS)) Index: llvm/tools/llvm-tapi-diff/DiffEngine.cpp =================================================================== --- llvm/tools/llvm-tapi-diff/DiffEngine.cpp +++ llvm/tools/llvm-tapi-diff/DiffEngine.cpp @@ -219,7 +219,7 @@ Order); diffAttribute("Parent Umbrellas", Output, Interface->umbrellas(), Order); diffAttribute("Symbols", Output, Interface->symbols(), Order); - for (auto Doc : Interface->documents()) { + for (const auto &Doc : Interface->documents()) { DiffOutput Documents("Inlined Reexported Frameworks/Libraries"); Documents.Kind = AD_Inline_Doc; Documents.Values.push_back(std::make_unique( Index: llvm/tools/llvm-xray/xray-converter.cpp =================================================================== --- llvm/tools/llvm-xray/xray-converter.cpp +++ llvm/tools/llvm-xray/xray-converter.cpp @@ -190,7 +190,7 @@ SmallVector Siblings{}; if (parent == nullptr) { - for (auto map_iter : StackRootsByThreadId) { + for (const auto &map_iter : StackRootsByThreadId) { // Only look for siblings in other threads. if (map_iter.first != TId) for (auto node_iter : map_iter.second) { Index: llvm/tools/llvm-xray/xray-fdr-dump.cpp =================================================================== --- llvm/tools/llvm-xray/xray-fdr-dump.cpp +++ llvm/tools/llvm-xray/xray-fdr-dump.cpp @@ -101,7 +101,7 @@ // Then we validate while printing each block. BlockVerifier BV; - for (auto ProcessThreadBlocks : Index) { + for (const auto &ProcessThreadBlocks : Index) { auto &Blocks = ProcessThreadBlocks.second; for (auto &B : Blocks) { for (auto *R : B.Records) { Index: llvm/tools/llvm-xray/xray-stacks.cpp =================================================================== --- llvm/tools/llvm-xray/xray-stacks.cpp +++ llvm/tools/llvm-xray/xray-stacks.cpp @@ -478,7 +478,7 @@ /// Prints top stacks for each thread. void printPerThread(raw_ostream &OS, FuncIdConversionHelper &FN) { - for (auto iter : Roots) { + for (const auto &iter : Roots) { OS << "Thread " << iter.first << ":\n"; print(OS, FN, iter.second); OS << "\n"; @@ -489,7 +489,7 @@ template void printAllPerThread(raw_ostream &OS, FuncIdConversionHelper &FN, StackOutputFormat format) { - for (auto iter : Roots) { + for (const auto &iter : Roots) { uint32_t threadId = iter.first; RootVector &perThreadRoots = iter.second; bool reportThreadId = true; @@ -521,7 +521,7 @@ /// thread IDs. RootVector mergeAcrossThreads(std::forward_list &NodeStore) { RootVector MergedByThreadRoots; - for (auto MapIter : Roots) { + for (const auto &MapIter : Roots) { const auto &RootNodeVector = MapIter.second; for (auto *Node : RootNodeVector) { auto MaybeFoundIter = Index: llvm/tools/obj2yaml/dwarf2yaml.cpp =================================================================== --- llvm/tools/obj2yaml/dwarf2yaml.cpp +++ llvm/tools/obj2yaml/dwarf2yaml.cpp @@ -26,10 +26,10 @@ auto AbbrevSetPtr = DCtx.getDebugAbbrev(); if (AbbrevSetPtr) { uint64_t AbbrevTableID = 0; - for (auto AbbrvDeclSet : *AbbrevSetPtr) { + for (const auto &AbbrvDeclSet : *AbbrevSetPtr) { Y.DebugAbbrev.emplace_back(); Y.DebugAbbrev.back().ID = AbbrevTableID++; - for (auto AbbrvDecl : AbbrvDeclSet.second) { + for (const auto &AbbrvDecl : AbbrvDeclSet.second) { DWARFYAML::Abbrev Abbrv; Abbrv.Code = AbbrvDecl.getCode(); Abbrv.Tag = AbbrvDecl.getTag(); Index: llvm/unittests/ADT/IteratorTest.cpp =================================================================== --- llvm/unittests/ADT/IteratorTest.cpp +++ llvm/unittests/ADT/IteratorTest.cpp @@ -269,7 +269,7 @@ int A[] = {0, 1, 2, 3, 4, 5, 6}; auto Enumerate = llvm::enumerate(A); SmallVector Actual; - for (auto IndexedValue : make_filter_range(Enumerate, IsOdd)) + for (const auto &IndexedValue : make_filter_range(Enumerate, IsOdd)) Actual.push_back(IndexedValue.value()); EXPECT_EQ((SmallVector{1, 3, 5}), Actual); } Index: llvm/unittests/ADT/STLExtrasTest.cpp =================================================================== --- llvm/unittests/ADT/STLExtrasTest.cpp +++ llvm/unittests/ADT/STLExtrasTest.cpp @@ -82,7 +82,7 @@ // the enumeration iterator. std::vector foo = {'a', 'b', 'c'}; - for (auto X : llvm::enumerate(foo)) { + for (const auto &X : llvm::enumerate(foo)) { ++X.value(); } EXPECT_THAT(foo, ElementsAre('b', 'c', 'd')); @@ -103,7 +103,7 @@ auto Enumerator = llvm::enumerate(std::vector{1, 2, 3}); - for (auto X : llvm::enumerate(std::vector{1, 2, 3})) { + for (const auto &X : llvm::enumerate(std::vector{1, 2, 3})) { Results.emplace_back(X.index(), X.value()); } @@ -128,7 +128,7 @@ typedef std::pair PairType; std::vector Results; - for (auto X : llvm::enumerate(std::vector{'1', '2', '3'})) { + for (const auto &X : llvm::enumerate(std::vector{'1', '2', '3'})) { ++X.value(); Results.emplace_back(X.index(), X.value()); } Index: llvm/unittests/DebugInfo/CodeView/RandomAccessVisitorTest.cpp =================================================================== --- llvm/unittests/DebugInfo/CodeView/RandomAccessVisitorTest.cpp +++ llvm/unittests/DebugInfo/CodeView/RandomAccessVisitorTest.cpp @@ -224,7 +224,7 @@ // 5, 5, 5 EXPECT_EQ(3u, TestState->Callbacks.count()); - for (auto I : enumerate(IndicesToVisit)) + for (const auto &I : enumerate(IndicesToVisit)) EXPECT_TRUE(ValidateVisitedRecord(I.index(), I.value())); } @@ -253,7 +253,7 @@ // 2, 4, 7 EXPECT_EQ(3u, TestState->Callbacks.count()); - for (auto I : enumerate(IndicesToVisit)) + for (const auto &I : enumerate(IndicesToVisit)) EXPECT_TRUE(ValidateVisitedRecord(I.index(), I.value())); } @@ -313,7 +313,7 @@ // [0, 2] EXPECT_EQ(3u, TestState->Callbacks.count()); - for (auto I : enumerate(IndicesToVisit)) + for (const auto &I : enumerate(IndicesToVisit)) EXPECT_TRUE(ValidateVisitedRecord(I.index(), I.value())); } Index: llvm/unittests/FileCheck/FileCheckTest.cpp =================================================================== --- llvm/unittests/FileCheck/FileCheckTest.cpp +++ llvm/unittests/FileCheck/FileCheckTest.cpp @@ -1764,7 +1764,7 @@ std::vector Diags; Tester.printVariableDefs(FileCheckDiag::MatchFoundAndExpected, Diags); EXPECT_EQ(Diags.size(), 2ul); - for (FileCheckDiag Diag : Diags) { + for (const FileCheckDiag &Diag : Diags) { EXPECT_EQ(Diag.CheckTy, Check::CheckPlain); EXPECT_EQ(Diag.MatchTy, FileCheckDiag::MatchFoundAndExpected); EXPECT_EQ(Diag.InputStartLine, 1u); Index: llvm/utils/FileCheck/FileCheck.cpp =================================================================== --- llvm/utils/FileCheck/FileCheck.cpp +++ llvm/utils/FileCheck/FileCheck.cpp @@ -390,7 +390,7 @@ }; // How many diagnostics does each pattern have? std::map DiagCountPerPattern; - for (auto Diag : Diags) + for (const auto &Diag : Diags) ++DiagCountPerPattern[Diag.CheckLoc]; // How many diagnostics have we seen so far per pattern? std::map DiagIndexPerPattern; @@ -673,7 +673,7 @@ for (unsigned Col = 1; InputFilePtr != InputFileEnd && !Newline; ++Col) { bool WasInMatch = InMatch; InMatch = false; - for (auto M : FoundAndExpectedMatches) { + for (const auto &M : FoundAndExpectedMatches) { if (M.InputStartCol <= Col && Col < M.InputEndCol) { InMatch = true; break; Index: llvm/utils/TableGen/InstrInfoEmitter.cpp =================================================================== --- llvm/utils/TableGen/InstrInfoEmitter.cpp +++ llvm/utils/TableGen/InstrInfoEmitter.cpp @@ -481,7 +481,7 @@ SizeToOperandName[Size].push_back(Op->getName()); } OS << " default: return 0;\n"; - for (auto KV : SizeToOperandName) { + for (const auto &KV : SizeToOperandName) { for (const StringRef &OperandName : KV.second) OS << " case OpTypes::" << OperandName << ":\n"; OS << " return " << KV.first << ";\n\n"; Index: llvm/utils/TableGen/IntrinsicEmitter.cpp =================================================================== --- llvm/utils/TableGen/IntrinsicEmitter.cpp +++ llvm/utils/TableGen/IntrinsicEmitter.cpp @@ -156,7 +156,7 @@ << " size_t Count;\n" << "};\n"; OS << "static constexpr IntrinsicTargetInfo TargetInfos[] = {\n"; - for (auto Target : Ints.Targets) + for (const auto &Target : Ints.Targets) OS << " {llvm::StringLiteral(\"" << Target.Name << "\"), " << Target.Offset << ", " << Target.Count << "},\n"; OS << "};\n";