[clang] e68fc86 - [NFCI][Offload Bundler] Replace hand-rolled endian conversion with llvm::support

Benjamin Kramer via cfe-commits cfe-commits at lists.llvm.org
Sun Jan 8 08:37:51 PST 2023


Author: Benjamin Kramer
Date: 2023-01-08T17:37:02+01:00
New Revision: e68fc86b22fd92f15c464b69e8d98a76f139cebd

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

LOG: [NFCI][Offload Bundler] Replace hand-rolled endian conversion with llvm::support

Added: 
    

Modified: 
    clang/lib/Driver/OffloadBundler.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Driver/OffloadBundler.cpp b/clang/lib/Driver/OffloadBundler.cpp
index 86fc4df5914a..7cffe4008b8e 100644
--- a/clang/lib/Driver/OffloadBundler.cpp
+++ b/clang/lib/Driver/OffloadBundler.cpp
@@ -29,8 +29,8 @@
 #include "llvm/Object/Binary.h"
 #include "llvm/Object/ObjectFile.h"
 #include "llvm/Support/Casting.h"
-#include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Debug.h"
+#include "llvm/Support/EndianStream.h"
 #include "llvm/Support/Errc.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/ErrorOr.h"
@@ -297,24 +297,12 @@ class FileHandler {
 
 /// Read 8-byte integers from a buffer in little-endian format.
 static uint64_t Read8byteIntegerFromBuffer(StringRef Buffer, size_t pos) {
-  uint64_t Res = 0;
-  const char *Data = Buffer.data();
-
-  for (unsigned i = 0; i < 8; ++i) {
-    Res <<= 8;
-    uint64_t Char = (uint64_t)Data[pos + 7 - i];
-    Res |= 0xffu & Char;
-  }
-  return Res;
+  return llvm::support::endian::read64le(Buffer.data() + pos);
 }
 
 /// Write 8-byte integers to a buffer in little-endian format.
 static void Write8byteIntegerToBuffer(raw_fd_ostream &OS, uint64_t Val) {
-  for (unsigned i = 0; i < 8; ++i) {
-    char Char = (char)(Val & 0xffu);
-    OS.write(&Char, 1);
-    Val >>= 8;
-  }
+  llvm::support::endian::write(OS, Val, llvm::support::little);
 }
 
 class BinaryFileHandler final : public FileHandler {


        


More information about the cfe-commits mailing list