Index: llvm/trunk/include/llvm/Support/Endian.h =================================================================== --- llvm/trunk/include/llvm/Support/Endian.h +++ llvm/trunk/include/llvm/Support/Endian.h @@ -338,6 +338,17 @@ using unaligned_int64_t = detail::packed_endian_specific_integral; +template +using little_t = detail::packed_endian_specific_integral; +template +using big_t = detail::packed_endian_specific_integral; + +template +using aligned_little_t = + detail::packed_endian_specific_integral; +template +using aligned_big_t = detail::packed_endian_specific_integral; + namespace endian { template inline T read(const void *P, endianness E) { Index: llvm/trunk/include/llvm/Support/SwapByteOrder.h =================================================================== --- llvm/trunk/include/llvm/Support/SwapByteOrder.h +++ llvm/trunk/include/llvm/Support/SwapByteOrder.h @@ -115,6 +115,13 @@ return out.d; } +template +inline typename std::enable_if::value, T>::type +getSwappedBytes(T C) { + return static_cast( + getSwappedBytes(static_cast::type>(C))); +} + template inline void swapByteOrder(T &Value) { Value = getSwappedBytes(Value); Index: llvm/trunk/unittests/Support/EndianTest.cpp =================================================================== --- llvm/trunk/unittests/Support/EndianTest.cpp +++ llvm/trunk/unittests/Support/EndianTest.cpp @@ -200,4 +200,13 @@ EXPECT_EQ(*big_val, *little_val); } +TEST(Endian, PacketEndianSpecificIntegralAsEnum) { + enum class Test : uint16_t { ONETWO = 0x0102, TWOONE = 0x0201 }; + unsigned char bytes[] = {0x01, 0x02}; + using LittleTest = little_t; + using BigTest = big_t; + EXPECT_EQ(Test::TWOONE, *reinterpret_cast(bytes)); + EXPECT_EQ(Test::ONETWO, *reinterpret_cast(bytes)); +} + } // end anon namespace