From: Chris Lattner Date: Thu, 22 Jan 2009 23:50:07 +0000 (+0000) Subject: remove my gross #ifdef's, using portable abstractions now that the 32-bit X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6f78c3b8b9343e7e9fbf2d457cccf00df6da5d47;p=clang remove my gross #ifdef's, using portable abstractions now that the 32-bit load is always aligned. I verified that the bswap doesn't occur in the assembly code on x86. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62815 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Lex/PTHLexer.cpp b/lib/Lex/PTHLexer.cpp index 497e225b47..51d49cf6e2 100644 --- a/lib/Lex/PTHLexer.cpp +++ b/lib/Lex/PTHLexer.cpp @@ -19,10 +19,12 @@ #include "clang/Lex/PTHManager.h" #include "clang/Lex/Token.h" #include "clang/Lex/Preprocessor.h" -#include "llvm/Support/Compiler.h" -#include "llvm/Support/MemoryBuffer.h" #include "llvm/ADT/StringMap.h" #include "llvm/ADT/OwningPtr.h" +#include "llvm/Support/Compiler.h" +#include "llvm/Support/MathExtras.h" +#include "llvm/Support/MemoryBuffer.h" +#include "llvm/System/Host.h" using namespace clang; #define DISK_TOKEN_SIZE (1+1+2+4+4) @@ -39,16 +41,11 @@ static inline uint16_t ReadUnalignedLE16(const unsigned char *&Data) { } static inline uint32_t ReadLE32(const unsigned char *&Data) { -// Targets that directly support unaligned little-endian 32-bit loads can just -// use them. -#if defined(__i386__) || defined(__x86_64__) + // Hosts that directly support unaligned little-endian 32-bit loads can just + // use them. uint32_t V = *((uint32_t*)Data); -#else - uint32_t V = ((uint32_t)Data[0] << 0) | - ((uint32_t)Data[1] << 8) | - ((uint32_t)Data[2] << 16) | - ((uint32_t)Data[3] << 24); -#endif + if (llvm::sys::isBigEndianHost()) + V = llvm::ByteSwap_32(V); Data += 4; return V; }