[llvm] 2cf3d05 - [MC] Simplify WasmObjectWriter

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sat Dec 21 21:59:36 PST 2024


Author: Fangrui Song
Date: 2024-12-21T21:59:31-08:00
New Revision: 2cf3d059176d7d92a096c32b15946a101d037c59

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

LOG: [MC] Simplify WasmObjectWriter

and make it fit well with the future when MCFragment content is
out-of-line.

Added: 
    

Modified: 
    llvm/lib/MC/WasmObjectWriter.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/MC/WasmObjectWriter.cpp b/llvm/lib/MC/WasmObjectWriter.cpp
index 85264692456767..29a8c53d350a40 100644
--- a/llvm/lib/MC/WasmObjectWriter.cpp
+++ b/llvm/lib/MC/WasmObjectWriter.cpp
@@ -734,12 +734,9 @@ static void addData(SmallVectorImpl<char> &DataBytes,
       DataBytes.insert(DataBytes.end(), Fill->getValueSize() * NumValues,
                        Fill->getValue());
     } else if (auto *LEB = dyn_cast<MCLEBFragment>(&Frag)) {
-      const SmallVectorImpl<char> &Contents = LEB->getContents();
-      llvm::append_range(DataBytes, Contents);
+      llvm::append_range(DataBytes, LEB->getContents());
     } else {
-      const auto &DataFrag = cast<MCDataFragment>(Frag);
-      const SmallVectorImpl<char> &Contents = DataFrag.getContents();
-      llvm::append_range(DataBytes, Contents);
+      llvm::append_range(DataBytes, cast<MCDataFragment>(Frag).getContents());
     }
   }
 
@@ -1896,14 +1893,7 @@ uint64_t WasmObjectWriter::writeOneObject(MCAssembler &Asm,
           report_fatal_error("invalid .init_array section priority");
       }
       const auto &DataFrag = cast<MCDataFragment>(Frag);
-      const SmallVectorImpl<char> &Contents = DataFrag.getContents();
-      for (const uint8_t *
-               P = (const uint8_t *)Contents.data(),
-              *End = (const uint8_t *)Contents.data() + Contents.size();
-           P != End; ++P) {
-        if (*P != 0)
-          report_fatal_error("non-symbolic data in .init_array section");
-      }
+      assert(llvm::all_of(DataFrag.getContents(), [](char C) { return !C; }));
       for (const MCFixup &Fixup : DataFrag.getFixups()) {
         assert(Fixup.getKind() ==
                MCFixup::getKindForSize(is64Bit() ? 8 : 4, false));


        


More information about the llvm-commits mailing list