[llvm-commits] [llvm] r171406 - in /llvm/trunk: include/llvm/Support/Compiler.h include/llvm/Support/Endian.h unittests/Support/EndianTest.cpp utils/yaml2obj/yaml2obj.cpp
David Dean
david_dean at apple.com
Wed Jan 2 15:41:16 PST 2013
Two tests are failing when using a Debug+Asserts compiler after this commit:
******************** TEST 'LLVM :: Object/archive-long-index.test' FAILED ********************Script:
--
/Users/buildslave/zorg/buildbot/smooshlab/slave-0.8/build.clang-x86_64-darwin10-DA/clang-build/Debug+Asserts/bin/llvm-nm -s /Users/buildslave/zorg/buildbot/smooshlab/slave-0.8/build.clang-x86_64-darwin10-DA/llvm/test/Object/Inputs/liblong_filenames.a | /Users/buildslave/zorg/buildbot/smooshlab/slave-0.8/build.clang-x86_64-darwin10-DA/clang-build/Debug+Asserts/bin/FileCheck -check-prefix=CHECKIDX /Users/buildslave/zorg/buildbot/smooshlab/slave-0.8/build.clang-x86_64-darwin10-DA/llvm/test/Object/archive-long-index.test
--
Exit Code: 1
Command Output (stderr):
--
LLVM ERROR: Section header table goes past end of file!
/Users/buildslave/zorg/buildbot/smooshlab/slave-0.8/build.clang-x86_64-darwin10-DA/llvm/test/Object/archive-long-index.test:19:11: error: expected string not found in input
CHECKIDX: 1.o:
^
<stdin>:15:1: note: scanning from here
^
--
********************
******************** TEST 'LLVM :: Object/simple-archive.test' FAILED ********************Script:
--
/Users/buildslave/zorg/buildbot/smooshlab/slave-0.8/build.clang-x86_64-darwin10-DA/clang-build/Debug+Asserts/bin/llvm-nm -s /Users/buildslave/zorg/buildbot/smooshlab/slave-0.8/build.clang-x86_64-darwin10-DA/llvm/test/Object/Inputs/libsimple_archive.a | /Users/buildslave/zorg/buildbot/smooshlab/slave-0.8/build.clang-x86_64-darwin10-DA/clang-build/Debug+Asserts/bin/FileCheck -check-prefix=CHECKIDX /Users/buildslave/zorg/buildbot/smooshlab/slave-0.8/build.clang-x86_64-darwin10-DA/llvm/test/Object/simple-archive.test
--
Exit Code: 1
Command Output (stderr):
--
LLVM ERROR: Section header table goes past end of file!
/Users/buildslave/zorg/buildbot/smooshlab/slave-0.8/build.clang-x86_64-darwin10-DA/llvm/test/Object/simple-archive.test:9:11: error: expected string not found in input
CHECKIDX: 1.o:
^
<stdin>:5:1: note: scanning from here
^
--
********************
On 2 Jan 2013, at 12:14 PM, Michael J. Spencer <bigcheesegs at gmail.com> wrote:
> Author: mspencer
> Date: Wed Jan 2 14:14:11 2013
> New Revision: 171406
>
> URL: http://llvm.org/viewvc/llvm-project?rev=171406&view=rev
> Log:
> [Support][Endian] Add support for specifying the alignment and native unaligned types.
>
> * Add support for specifying the alignment to use.
> * Add the concept of native endianness. Used for unaligned native types.
>
> The native alignment and read/write simplification is based on a patch by Richard Smith.
>
> Modified:
> llvm/trunk/include/llvm/Support/Compiler.h
> llvm/trunk/include/llvm/Support/Endian.h
> llvm/trunk/unittests/Support/EndianTest.cpp
> llvm/trunk/utils/yaml2obj/yaml2obj.cpp
>
> Modified: llvm/trunk/include/llvm/Support/Compiler.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/Compiler.h?rev=171406&r1=171405&r2=171406&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/Support/Compiler.h (original)
> +++ llvm/trunk/include/llvm/Support/Compiler.h Wed Jan 2 14:14:11 2013
> @@ -151,7 +151,6 @@
> #define LLVM_UNLIKELY(EXPR) (EXPR)
> #endif
>
> -
> // C++ doesn't support 'extern template' of template specializations. GCC does,
> // but requires __extension__ before it. In the header, use this:
> // EXTERN_TEMPLATE_INSTANTIATION(class foo<bar>);
> @@ -187,7 +186,6 @@
> #define LLVM_ATTRIBUTE_ALWAYS_INLINE
> #endif
>
> -
> #ifdef __GNUC__
> #define LLVM_ATTRIBUTE_NORETURN __attribute__((noreturn))
> #elif defined(_MSC_VER)
> @@ -225,6 +223,10 @@
> #if defined(__clang__) || (__GNUC__ > 4) \
> || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
> # define LLVM_BUILTIN_UNREACHABLE __builtin_unreachable()
> +#elif defined(_MSC_VER)
> +# define LLVM_BUILTIN_UNREACHABLE __assume(false)
> +#else
> +# define LLVM_BUILTIN_UNREACHABLE 0
> #endif
>
> /// LLVM_BUILTIN_TRAP - On compilers which support it, expands to an expression
> @@ -236,4 +238,14 @@
> # define LLVM_BUILTIN_TRAP *(volatile int*)0x11 = 0
> #endif
>
> +/// \macro LLVM_ASSUME_ALIGNED
> +/// \brief Returns a pointer with an assumed alignment.
> +#if defined(__GNUC__) && !defined(__clang__)
> +// FIXME: Enable on clang when it supports it.
> +# define LLVM_ASSUME_ALIGNED(p, a) __builtin_assume_aligned(p, a)
> +#else
> +# define LLVM_ASSUME_ALIGNED(p, a) \
> + (((uintptr_t(p) % (a)) == 0) ? (p) : (LLVM_BUILTIN_UNREACHABLE, (p)))
> +#endif
> +
> #endif
>
> Modified: llvm/trunk/include/llvm/Support/Endian.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/Endian.h?rev=171406&r1=171405&r2=171406&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/Support/Endian.h (original)
> +++ llvm/trunk/include/llvm/Support/Endian.h Wed Jan 2 14:14:11 2013
> @@ -14,136 +14,78 @@
> #ifndef LLVM_SUPPORT_ENDIAN_H
> #define LLVM_SUPPORT_ENDIAN_H
>
> +#include "llvm/Support/AlignOf.h"
> #include "llvm/Support/Host.h"
> #include "llvm/Support/SwapByteOrder.h"
> #include "llvm/Support/type_traits.h"
>
> namespace llvm {
> namespace support {
> +enum endianness {big, little, native};
>
> -enum endianness {big, little};
> -enum alignment {unaligned, aligned};
> +// These are named values for common alignments.
> +enum {aligned = 0, unaligned = 1};
>
> namespace detail {
> -
> -template<typename value_type, alignment align>
> -struct alignment_access_helper;
> -
> -template<typename value_type>
> -struct alignment_access_helper<value_type, aligned>
> -{
> - value_type val;
> -};
> -
> -// Provides unaligned loads and stores.
> -#pragma pack(push)
> -#pragma pack(1)
> -template<typename value_type>
> -struct alignment_access_helper<value_type, unaligned>
> -{
> - value_type val;
> -};
> -#pragma pack(pop)
> -
> + /// \brief ::value is either alignment, or alignof(T) if alignment is 0.
> + template<class T, int alignment>
> + struct PickAlignment {
> + enum {value = alignment == 0 ? AlignOf<T>::Alignment : alignment};
> + };
> } // end namespace detail
>
> namespace endian {
> - template<typename value_type, alignment align>
> - inline value_type read_le(const void *memory) {
> - value_type t =
> - reinterpret_cast<const detail::alignment_access_helper
> - <value_type, align> *>(memory)->val;
> - if (sys::isBigEndianHost())
> - return sys::SwapByteOrder(t);
> - return t;
> - }
> -
> - template<typename value_type, alignment align>
> - inline void write_le(void *memory, value_type value) {
> - if (sys::isBigEndianHost())
> - value = sys::SwapByteOrder(value);
> - reinterpret_cast<detail::alignment_access_helper<value_type, align> *>
> - (memory)->val = value;
> - }
> +template<typename value_type, endianness endian>
> +inline value_type byte_swap(value_type value) {
> + if (endian != native && sys::isBigEndianHost() != (endian == big))
> + return sys::SwapByteOrder(value);
> + return value;
> +}
>
> - template<typename value_type, alignment align>
> - inline value_type read_be(const void *memory) {
> - value_type t =
> - reinterpret_cast<const detail::alignment_access_helper
> - <value_type, align> *>(memory)->val;
> - if (sys::isLittleEndianHost())
> - return sys::SwapByteOrder(t);
> - return t;
> - }
> +template<typename value_type,
> + endianness endian,
> + std::size_t alignment>
> +inline value_type read(const void *memory) {
> + value_type ret;
> +
> + memcpy(&ret,
> + LLVM_ASSUME_ALIGNED(memory,
> + (detail::PickAlignment<value_type, alignment>::value)),
> + sizeof(value_type));
> + return byte_swap<value_type, endian>(ret);
> +}
>
> - template<typename value_type, alignment align>
> - inline void write_be(void *memory, value_type value) {
> - if (sys::isLittleEndianHost())
> - value = sys::SwapByteOrder(value);
> - reinterpret_cast<detail::alignment_access_helper<value_type, align> *>
> - (memory)->val = value;
> - }
> +template<typename value_type,
> + endianness endian,
> + std::size_t alignment>
> +inline void write(void *memory, value_type value) {
> + value = byte_swap<value_type, endian>(value);
> + memcpy(LLVM_ASSUME_ALIGNED(memory,
> + (detail::PickAlignment<value_type, alignment>::value)),
> + &value,
> + sizeof(value_type));
> }
> +} // end namespace endian
>
> namespace detail {
> -
> template<typename value_type,
> endianness endian,
> - alignment align>
> -class packed_endian_specific_integral;
> -
> -template<typename value_type>
> -class packed_endian_specific_integral<value_type, little, unaligned> {
> -public:
> - operator value_type() const {
> - return endian::read_le<value_type, unaligned>(Value);
> - }
> - void operator=(value_type newValue) {
> - endian::write_le<value_type, unaligned>((void *)&Value, newValue);
> - }
> -private:
> - uint8_t Value[sizeof(value_type)];
> -};
> -
> -template<typename value_type>
> -class packed_endian_specific_integral<value_type, big, unaligned> {
> -public:
> + std::size_t alignment>
> +struct packed_endian_specific_integral {
> operator value_type() const {
> - return endian::read_be<value_type, unaligned>(Value);
> + return endian::read<value_type, endian, alignment>(
> + (const void*)Value.buffer);
> }
> - void operator=(value_type newValue) {
> - endian::write_be<value_type, unaligned>((void *)&Value, newValue);
> - }
> -private:
> - uint8_t Value[sizeof(value_type)];
> -};
>
> -template<typename value_type>
> -class packed_endian_specific_integral<value_type, little, aligned> {
> -public:
> - operator value_type() const {
> - return endian::read_le<value_type, aligned>(&Value);
> - }
> void operator=(value_type newValue) {
> - endian::write_le<value_type, aligned>((void *)&Value, newValue);
> + endian::write<value_type, endian, alignment>(
> + (void*)Value.buffer, newValue);
> }
> -private:
> - value_type Value;
> -};
>
> -template<typename value_type>
> -class packed_endian_specific_integral<value_type, big, aligned> {
> -public:
> - operator value_type() const {
> - return endian::read_be<value_type, aligned>(&Value);
> - }
> - void operator=(value_type newValue) {
> - endian::write_be<value_type, aligned>((void *)&Value, newValue);
> - }
> private:
> - value_type Value;
> + AlignedCharArray<PickAlignment<value_type, alignment>::value,
> + sizeof(value_type)> Value;
> };
> -
> } // end namespace detail
>
> typedef detail::packed_endian_specific_integral
> @@ -218,6 +160,19 @@
> typedef detail::packed_endian_specific_integral
> <int64_t, big, aligned> aligned_big64_t;
>
> +typedef detail::packed_endian_specific_integral
> + <uint16_t, native, unaligned> unaligned_uint16_t;
> +typedef detail::packed_endian_specific_integral
> + <uint32_t, native, unaligned> unaligned_uint32_t;
> +typedef detail::packed_endian_specific_integral
> + <uint64_t, native, unaligned> unaligned_uint64_t;
> +
> +typedef detail::packed_endian_specific_integral
> + <int16_t, native, unaligned> unaligned_int16_t;
> +typedef detail::packed_endian_specific_integral
> + <int32_t, native, unaligned> unaligned_int32_t;
> +typedef detail::packed_endian_specific_integral
> + <int64_t, native, unaligned> unaligned_int64_t;
> } // end namespace llvm
> } // end namespace support
>
>
> Modified: llvm/trunk/unittests/Support/EndianTest.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/EndianTest.cpp?rev=171406&r1=171405&r2=171406&view=diff
> ==============================================================================
> --- llvm/trunk/unittests/Support/EndianTest.cpp (original)
> +++ llvm/trunk/unittests/Support/EndianTest.cpp Wed Jan 2 14:14:11 2013
> @@ -21,36 +21,36 @@
>
> TEST(Endian, Read) {
> // These are 5 bytes so we can be sure at least one of the reads is unaligned.
> - unsigned char big[] = {0x00, 0x01, 0x02, 0x03, 0x04};
> - unsigned char little[] = {0x00, 0x04, 0x03, 0x02, 0x01};
> + unsigned char bigval[] = {0x00, 0x01, 0x02, 0x03, 0x04};
> + unsigned char littleval[] = {0x00, 0x04, 0x03, 0x02, 0x01};
> int32_t BigAsHost = 0x00010203;
> - EXPECT_EQ(BigAsHost, (endian::read_be<int32_t, unaligned>(big)));
> + EXPECT_EQ(BigAsHost, (endian::read<int32_t, big, unaligned>(bigval)));
> int32_t LittleAsHost = 0x02030400;
> - EXPECT_EQ(LittleAsHost, (endian::read_le<int32_t, unaligned>(little)));
> + EXPECT_EQ(LittleAsHost,(endian::read<int32_t, little, unaligned>(littleval)));
>
> - EXPECT_EQ((endian::read_be<int32_t, unaligned>(big + 1)),
> - (endian::read_le<int32_t, unaligned>(little + 1)));
> + EXPECT_EQ((endian::read<int32_t, big, unaligned>(bigval + 1)),
> + (endian::read<int32_t, little, unaligned>(littleval + 1)));
> }
>
> TEST(Endian, Write) {
> unsigned char data[5];
> - endian::write_be<int32_t, unaligned>(data, -1362446643);
> + endian::write<int32_t, big, unaligned>(data, -1362446643);
> EXPECT_EQ(data[0], 0xAE);
> EXPECT_EQ(data[1], 0xCA);
> EXPECT_EQ(data[2], 0xB6);
> EXPECT_EQ(data[3], 0xCD);
> - endian::write_be<int32_t, unaligned>(data + 1, -1362446643);
> + endian::write<int32_t, big, unaligned>(data + 1, -1362446643);
> EXPECT_EQ(data[1], 0xAE);
> EXPECT_EQ(data[2], 0xCA);
> EXPECT_EQ(data[3], 0xB6);
> EXPECT_EQ(data[4], 0xCD);
>
> - endian::write_le<int32_t, unaligned>(data, -1362446643);
> + endian::write<int32_t, little, unaligned>(data, -1362446643);
> EXPECT_EQ(data[0], 0xCD);
> EXPECT_EQ(data[1], 0xB6);
> EXPECT_EQ(data[2], 0xCA);
> EXPECT_EQ(data[3], 0xAE);
> - endian::write_le<int32_t, unaligned>(data + 1, -1362446643);
> + endian::write<int32_t, little, unaligned>(data + 1, -1362446643);
> EXPECT_EQ(data[1], 0xCD);
> EXPECT_EQ(data[2], 0xB6);
> EXPECT_EQ(data[3], 0xCA);
> @@ -69,4 +69,4 @@
> EXPECT_EQ(*big_val, *little_val);
> }
>
> -}
> +} // end anon namespace
>
> Modified: llvm/trunk/utils/yaml2obj/yaml2obj.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/yaml2obj/yaml2obj.cpp?rev=171406&r1=171405&r2=171406&view=diff
> ==============================================================================
> --- llvm/trunk/utils/yaml2obj/yaml2obj.cpp (original)
> +++ llvm/trunk/utils/yaml2obj/yaml2obj.cpp Wed Jan 2 14:14:11 2013
> @@ -790,7 +790,8 @@
> raw_ostream &operator <<( raw_ostream &OS
> , const binary_le_impl<value_type> &BLE) {
> char Buffer[sizeof(BLE.Value)];
> - support::endian::write_le<value_type, support::unaligned>(Buffer, BLE.Value);
> + support::endian::write<value_type, support::little, support::unaligned>(
> + Buffer, BLE.Value);
> OS.write(Buffer, sizeof(BLE.Value));
> return OS;
> }
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
-David
More information about the llvm-commits
mailing list