Skip to content

Commit e68fc86

Browse files
committed
[NFCI][Offload Bundler] Replace hand-rolled endian conversion with llvm::support
1 parent b6942a2 commit e68fc86

File tree

1 file changed

+3
-15
lines changed

1 file changed

+3
-15
lines changed

clang/lib/Driver/OffloadBundler.cpp

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
#include "llvm/Object/Binary.h"
3030
#include "llvm/Object/ObjectFile.h"
3131
#include "llvm/Support/Casting.h"
32-
#include "llvm/Support/CommandLine.h"
3332
#include "llvm/Support/Debug.h"
33+
#include "llvm/Support/EndianStream.h"
3434
#include "llvm/Support/Errc.h"
3535
#include "llvm/Support/Error.h"
3636
#include "llvm/Support/ErrorOr.h"
@@ -297,24 +297,12 @@ class FileHandler {
297297

298298
/// Read 8-byte integers from a buffer in little-endian format.
299299
static uint64_t Read8byteIntegerFromBuffer(StringRef Buffer, size_t pos) {
300-
uint64_t Res = 0;
301-
const char *Data = Buffer.data();
302-
303-
for (unsigned i = 0; i < 8; ++i) {
304-
Res <<= 8;
305-
uint64_t Char = (uint64_t)Data[pos + 7 - i];
306-
Res |= 0xffu & Char;
307-
}
308-
return Res;
300+
return llvm::support::endian::read64le(Buffer.data() + pos);
309301
}
310302

311303
/// Write 8-byte integers to a buffer in little-endian format.
312304
static void Write8byteIntegerToBuffer(raw_fd_ostream &OS, uint64_t Val) {
313-
for (unsigned i = 0; i < 8; ++i) {
314-
char Char = (char)(Val & 0xffu);
315-
OS.write(&Char, 1);
316-
Val >>= 8;
317-
}
305+
llvm::support::endian::write(OS, Val, llvm::support::little);
318306
}
319307

320308
class BinaryFileHandler final : public FileHandler {

0 commit comments

Comments
 (0)