[llvm] 6bf948c - [MC] Use range-based for loops (NFC) (#139354)

via llvm-commits llvm-commits at lists.llvm.org
Sat May 10 07:29:05 PDT 2025


Author: Kazu Hirata
Date: 2025-05-10T07:29:02-07:00
New Revision: 6bf948c2ece1bf5e78a8b11fd742e7938bb62e4e

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

LOG: [MC] Use range-based for loops (NFC) (#139354)

Added: 
    

Modified: 
    llvm/lib/MC/MCAssembler.cpp
    llvm/lib/MC/MCContext.cpp
    llvm/lib/MC/MCWasmStreamer.cpp
    llvm/lib/MC/MCWinCOFFStreamer.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/MC/MCAssembler.cpp b/llvm/lib/MC/MCAssembler.cpp
index eaaa57408becf..73c3a3a00b5c6 100644
--- a/llvm/lib/MC/MCAssembler.cpp
+++ b/llvm/lib/MC/MCAssembler.cpp
@@ -809,8 +809,8 @@ void MCAssembler::writeSectionData(raw_ostream &OS,
           getContext().reportError(SMLoc(), Sec->getVirtualSectionKind() +
                                                 " section '" + Sec->getName() +
                                                 "' cannot have fixups");
-        for (unsigned i = 0, e = DF.getContents().size(); i != e; ++i)
-          if (DF.getContents()[i]) {
+        for (char C : DF.getContents())
+          if (C) {
             getContext().reportError(SMLoc(),
                                      Sec->getVirtualSectionKind() +
                                          " section '" + Sec->getName() +

diff  --git a/llvm/lib/MC/MCContext.cpp b/llvm/lib/MC/MCContext.cpp
index 1a6f3b3c17ea0..cda1276497b51 100644
--- a/llvm/lib/MC/MCContext.cpp
+++ b/llvm/lib/MC/MCContext.cpp
@@ -477,10 +477,10 @@ MCSymbolXCOFF *MCContext::createXCOFFSymbolImpl(const MCSymbolTableEntry *Name,
 
   // Append the hex values of '_' and invalid characters with "_Renamed..";
   // at the same time replace invalid characters with '_'.
-  for (size_t I = 0; I < InvalidName.size(); ++I) {
-    if (!MAI->isAcceptableChar(InvalidName[I]) || InvalidName[I] == '_') {
-      raw_svector_ostream(ValidName).write_hex(InvalidName[I]);
-      InvalidName[I] = '_';
+  for (char &C : InvalidName) {
+    if (!MAI->isAcceptableChar(C) || C == '_') {
+      raw_svector_ostream(ValidName).write_hex(C);
+      C = '_';
     }
   }
 

diff  --git a/llvm/lib/MC/MCWasmStreamer.cpp b/llvm/lib/MC/MCWasmStreamer.cpp
index 117eae7e23b8e..cddd250cc0005 100644
--- a/llvm/lib/MC/MCWasmStreamer.cpp
+++ b/llvm/lib/MC/MCWasmStreamer.cpp
@@ -179,9 +179,9 @@ void MCWasmStreamer::emitInstToData(const MCInst &Inst,
   MCDataFragment *DF = getOrCreateDataFragment();
 
   // Add the fixups and data.
-  for (unsigned I = 0, E = Fixups.size(); I != E; ++I) {
-    Fixups[I].setOffset(Fixups[I].getOffset() + DF->getContents().size());
-    DF->getFixups().push_back(Fixups[I]);
+  for (MCFixup &Fixup : Fixups) {
+    Fixup.setOffset(Fixup.getOffset() + DF->getContents().size());
+    DF->getFixups().push_back(Fixup);
   }
   DF->setHasInstructions(STI);
   DF->appendContents(Code);

diff  --git a/llvm/lib/MC/MCWinCOFFStreamer.cpp b/llvm/lib/MC/MCWinCOFFStreamer.cpp
index 419ea6da426fd..e03f7b5b6d418 100644
--- a/llvm/lib/MC/MCWinCOFFStreamer.cpp
+++ b/llvm/lib/MC/MCWinCOFFStreamer.cpp
@@ -145,9 +145,9 @@ void MCWinCOFFStreamer::emitInstToData(const MCInst &Inst,
   getAssembler().getEmitter().encodeInstruction(Inst, Code, Fixups, STI);
 
   // Add the fixups and data.
-  for (unsigned i = 0, e = Fixups.size(); i != e; ++i) {
-    Fixups[i].setOffset(Fixups[i].getOffset() + DF->getContents().size());
-    DF->getFixups().push_back(Fixups[i]);
+  for (MCFixup &Fixup : Fixups) {
+    Fixup.setOffset(Fixup.getOffset() + DF->getContents().size());
+    DF->getFixups().push_back(Fixup);
   }
   DF->setHasInstructions(STI);
   DF->appendContents(Code);


        


More information about the llvm-commits mailing list