[llvm] Prefer const auto& to copying the entire object (PR #99830)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Jul 21 16:41:28 PDT 2024
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff 1a47f3f3db66589c11f8ddacfeaecc03fb80c510 8413e9748f356dc3b642cfc0f88dd5fdea4fa268 --extensions h,cpp -- llvm/lib/ExecutionEngine/Orc/Core.cpp llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp llvm/lib/Object/ArchiveWriter.cpp llvm/lib/ObjectYAML/DXContainerEmitter.cpp llvm/lib/Support/VirtualFileSystem.cpp llvm/lib/Transforms/Utils/CodeExtractor.cpp llvm/tools/llvm-readobj/ObjDumper.h llvm/tools/llvm-remarkutil/RemarkCounter.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/llvm/lib/ExecutionEngine/Orc/Core.cpp b/llvm/lib/ExecutionEngine/Orc/Core.cpp
index 56112312a5..2d90491c30 100644
--- a/llvm/lib/ExecutionEngine/Orc/Core.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/Core.cpp
@@ -1692,7 +1692,7 @@ Error ExecutionSession::removeJITDylibs(std::vector<JITDylibSP> JDsToRemove) {
// Clear JITDylibs and notify the platform.
Error Err = Error::success();
- for (const auto& JD : JDsToRemove) {
+ for (const auto &JD : JDsToRemove) {
Err = joinErrors(std::move(Err), JD->clear());
if (P)
Err = joinErrors(std::move(Err), P->teardownJITDylib(*JD));
diff --git a/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp b/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp
index 167b2527c3..f94e256e60 100644
--- a/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp
+++ b/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp
@@ -255,7 +255,7 @@ Error Object::compressOrDecompressSections(const CommonConfig &Config) {
}
DenseMap<SectionBase *, SectionBase *> FromTo;
- for (const auto& [S, Func] : ToReplace)
+ for (const auto &[S, Func] : ToReplace)
FromTo[S] = Func();
return replaceSections(FromTo);
}
diff --git a/llvm/lib/Object/ArchiveWriter.cpp b/llvm/lib/Object/ArchiveWriter.cpp
index 53343c1bdf..e34165ede5 100644
--- a/llvm/lib/Object/ArchiveWriter.cpp
+++ b/llvm/lib/Object/ArchiveWriter.cpp
@@ -415,7 +415,7 @@ static uint64_t computeSymbolMapSize(uint64_t NumObj, SymMap &SymMap,
uint64_t Size = sizeof(uint32_t) * 2; // Number of symbols and objects entries
Size += NumObj * sizeof(uint32_t); // Offset table
- for (const auto& S : SymMap.Map)
+ for (const auto &S : SymMap.Map)
Size += sizeof(uint16_t) + S.first.length() + 1;
uint32_t Pad = offsetToAlignment(Size, Align(2));
@@ -429,7 +429,7 @@ static uint64_t computeECSymbolsSize(SymMap &SymMap,
uint32_t *Padding = nullptr) {
uint64_t Size = sizeof(uint32_t); // Number of symbols
- for (const auto& S : SymMap.ECMap)
+ for (const auto &S : SymMap.ECMap)
Size += sizeof(uint16_t) + S.first.length() + 1;
uint32_t Pad = offsetToAlignment(Size, Align(2));
@@ -659,9 +659,9 @@ static void writeSymbolMap(raw_ostream &Out, object::Archive::Kind Kind,
printLE<uint32_t>(Out, SymMap.Map.size());
- for (const auto& S : SymMap.Map)
+ for (const auto &S : SymMap.Map)
printLE(Out, S.second);
- for (const auto& S : SymMap.Map)
+ for (const auto &S : SymMap.Map)
Out << S.first << '\0';
while (Pad--)
@@ -678,9 +678,9 @@ static void writeECSymbols(raw_ostream &Out, object::Archive::Kind Kind,
printLE<uint32_t>(Out, SymMap.ECMap.size());
- for (const auto& S : SymMap.ECMap)
+ for (const auto &S : SymMap.ECMap)
printLE(Out, S.second);
- for (const auto& S : SymMap.ECMap)
+ for (const auto &S : SymMap.ECMap)
Out << S.first << '\0';
while (Pad--)
Out.write(uint8_t(0));
diff --git a/llvm/lib/ObjectYAML/DXContainerEmitter.cpp b/llvm/lib/ObjectYAML/DXContainerEmitter.cpp
index a41b0ca3fb..8b23baf1bd 100644
--- a/llvm/lib/ObjectYAML/DXContainerEmitter.cpp
+++ b/llvm/lib/ObjectYAML/DXContainerEmitter.cpp
@@ -202,19 +202,19 @@ void DXContainerWriter::writeParts(raw_ostream &OS) {
PSV.Resources = P.Info->Resources;
PSV.EntryName = P.Info->EntryName;
- for (const auto& El : P.Info->SigInputElements)
+ for (const auto &El : P.Info->SigInputElements)
PSV.InputElements.push_back(mcdxbc::PSVSignatureElement{
El.Name, El.Indices, El.StartRow, El.Cols, El.StartCol,
El.Allocated, El.Kind, El.Type, El.Mode, El.DynamicMask,
El.Stream});
- for (const auto& El : P.Info->SigOutputElements)
+ for (const auto &El : P.Info->SigOutputElements)
PSV.OutputElements.push_back(mcdxbc::PSVSignatureElement{
El.Name, El.Indices, El.StartRow, El.Cols, El.StartCol,
El.Allocated, El.Kind, El.Type, El.Mode, El.DynamicMask,
El.Stream});
- for (const auto& El : P.Info->SigPatchOrPrimElements)
+ for (const auto &El : P.Info->SigPatchOrPrimElements)
PSV.PatchOrPrimElements.push_back(mcdxbc::PSVSignatureElement{
El.Name, El.Indices, El.StartRow, El.Cols, El.StartCol,
El.Allocated, El.Kind, El.Type, El.Mode, El.DynamicMask,
diff --git a/llvm/lib/Support/VirtualFileSystem.cpp b/llvm/lib/Support/VirtualFileSystem.cpp
index d9a3f86f08..a3997d8518 100644
--- a/llvm/lib/Support/VirtualFileSystem.cpp
+++ b/llvm/lib/Support/VirtualFileSystem.cpp
@@ -498,7 +498,7 @@ std::error_code OverlayFileSystem::getRealPath(const Twine &Path,
}
void OverlayFileSystem::visitChildFileSystems(VisitCallbackTy Callback) {
- for (const IntrusiveRefCntPtr<FileSystem>& FS : overlays_range()) {
+ for (const IntrusiveRefCntPtr<FileSystem> &FS : overlays_range()) {
Callback(*FS);
FS->visitChildFileSystems(Callback);
}
diff --git a/llvm/lib/Transforms/Utils/CodeExtractor.cpp b/llvm/lib/Transforms/Utils/CodeExtractor.cpp
index 3c22fd6b13..b9b4b617f6 100644
--- a/llvm/lib/Transforms/Utils/CodeExtractor.cpp
+++ b/llvm/lib/Transforms/Utils/CodeExtractor.cpp
@@ -1930,7 +1930,7 @@ CodeExtractor::extractCodeRegion(const CodeExtractorAnalysisCache &CEAC,
bool CodeExtractor::verifyAssumptionCache(const Function &OldFunc,
const Function &NewFunc,
AssumptionCache *AC) {
- for (const auto& AssumeVH : AC->assumptions()) {
+ for (const auto &AssumeVH : AC->assumptions()) {
auto *I = dyn_cast_or_null<CallInst>(AssumeVH);
if (!I)
continue;
diff --git a/llvm/tools/llvm-readobj/ObjDumper.h b/llvm/tools/llvm-readobj/ObjDumper.h
index f51e4ad03c..80d9844c9b 100644
--- a/llvm/tools/llvm-readobj/ObjDumper.h
+++ b/llvm/tools/llvm-readobj/ObjDumper.h
@@ -49,7 +49,7 @@ public:
void addPredicate(CompPredicate Pred) { Predicates.push_back(Pred); }
bool operator()(object::SymbolRef LHS, object::SymbolRef RHS) {
- for (const CompPredicate& Pred : Predicates) {
+ for (const CompPredicate &Pred : Predicates) {
if (Pred(LHS, RHS))
return true;
if (Pred(RHS, LHS))
diff --git a/llvm/tools/llvm-remarkutil/RemarkCounter.cpp b/llvm/tools/llvm-remarkutil/RemarkCounter.cpp
index b52bc03584..1caff5159d 100644
--- a/llvm/tools/llvm-remarkutil/RemarkCounter.cpp
+++ b/llvm/tools/llvm-remarkutil/RemarkCounter.cpp
@@ -222,7 +222,7 @@ Error ArgumentCounter::print(StringRef OutputFileName) {
Idx++;
}
OF->os() << "\n";
- for (const auto& [Header, CountVector] : CountByKeysMap) {
+ for (const auto &[Header, CountVector] : CountByKeysMap) {
OF->os() << Header << ",";
unsigned Idx = 0;
for (auto Count : CountVector) {
@@ -245,7 +245,7 @@ Error RemarkCounter::print(StringRef OutputFileName) {
auto OF = std::move(*MaybeOF);
OF->os() << groupByToStr(Group) << ","
<< "Count\n";
- for (const auto& [Key, Count] : CountedByRemarksMap)
+ for (const auto &[Key, Count] : CountedByRemarksMap)
OF->os() << Key << "," << Count << "\n";
OF->keep();
return Error::success();
@@ -319,7 +319,7 @@ static Error collectRemarks() {
for (auto &Key : Keys)
ArgumentsVector.push_back({Key, false});
} else if (!RKeys.empty())
- for (const auto& Key : RKeys)
+ for (const auto &Key : RKeys)
ArgumentsVector.push_back({Key, true});
else
ArgumentsVector.push_back({".*", true});
``````````
</details>
https://github.com/llvm/llvm-project/pull/99830
More information about the llvm-commits
mailing list