mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-22 13:29:44 +00:00
[support] Add a macro wrapper for alignas and simplify some code.
We wrap __attribute((aligned)) for GCC 4.7 and __declspec(align) for MSVC. The latter behaves weird in some contexts so this should be used carefully. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@233910 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
3fabd02ea5
commit
efdcf3d62d
@ -70,38 +70,11 @@ inline unsigned alignOf() { return AlignOf<T>::Alignment; }
|
|||||||
// MSVC requires special handling here.
|
// MSVC requires special handling here.
|
||||||
#ifndef _MSC_VER
|
#ifndef _MSC_VER
|
||||||
|
|
||||||
#if __has_feature(cxx_alignas)
|
|
||||||
template<std::size_t Alignment, std::size_t Size>
|
template<std::size_t Alignment, std::size_t Size>
|
||||||
struct AlignedCharArray {
|
struct AlignedCharArray {
|
||||||
alignas(Alignment) char buffer[Size];
|
LLVM_ALIGNAS(Alignment) char buffer[Size];
|
||||||
};
|
};
|
||||||
|
|
||||||
#elif defined(__GNUC__) || defined(__IBM_ATTRIBUTES)
|
|
||||||
/// \brief Create a type with an aligned char buffer.
|
|
||||||
template<std::size_t Alignment, std::size_t Size>
|
|
||||||
struct AlignedCharArray;
|
|
||||||
|
|
||||||
#define LLVM_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT(x) \
|
|
||||||
template<std::size_t Size> \
|
|
||||||
struct AlignedCharArray<x, Size> { \
|
|
||||||
__attribute__((aligned(x))) char buffer[Size]; \
|
|
||||||
};
|
|
||||||
|
|
||||||
LLVM_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT(1)
|
|
||||||
LLVM_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT(2)
|
|
||||||
LLVM_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT(4)
|
|
||||||
LLVM_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT(8)
|
|
||||||
LLVM_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT(16)
|
|
||||||
LLVM_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT(32)
|
|
||||||
LLVM_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT(64)
|
|
||||||
LLVM_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT(128)
|
|
||||||
|
|
||||||
#undef LLVM_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT
|
|
||||||
|
|
||||||
#else
|
|
||||||
# error No supported align as directive.
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#else // _MSC_VER
|
#else // _MSC_VER
|
||||||
|
|
||||||
/// \brief Create a type with an aligned char buffer.
|
/// \brief Create a type with an aligned char buffer.
|
||||||
|
@ -281,6 +281,20 @@
|
|||||||
# define LLVM_ASSUME_ALIGNED(p, a) (p)
|
# define LLVM_ASSUME_ALIGNED(p, a) (p)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/// \macro LLVM_ALIGNAS
|
||||||
|
/// \brief Used to specify a minimum alignment for a structure or variable. The
|
||||||
|
/// alignment must be a constant integer.
|
||||||
|
///
|
||||||
|
/// Note that __declspec(align) has special quirks, it's not legal to pass a
|
||||||
|
/// structure with __declspec(align) as a formal parameter.
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
# define LLVM_ALIGNAS(x) __declspec(align(x))
|
||||||
|
#elif __GNUC__ && !__has_feature(cxx_alignas) && !LLVM_GNUC_PREREQ(4, 8, 0)
|
||||||
|
# define LLVM_ALIGNAS(x) __attribute__((aligned(x)))
|
||||||
|
#else
|
||||||
|
# define LLVM_ALIGNAS(x) alignas(x)
|
||||||
|
#endif
|
||||||
|
|
||||||
/// \macro LLVM_FUNCTION_NAME
|
/// \macro LLVM_FUNCTION_NAME
|
||||||
/// \brief Expands to __func__ on compilers which support it. Otherwise,
|
/// \brief Expands to __func__ on compilers which support it. Otherwise,
|
||||||
/// expands to a compiler-dependent replacement.
|
/// expands to a compiler-dependent replacement.
|
||||||
|
@ -39,24 +39,10 @@ namespace {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Define some fixed alignment types to use in these tests.
|
// Define some fixed alignment types to use in these tests.
|
||||||
#if __has_feature(cxx_alignas)
|
struct LLVM_ALIGNAS(1) A1 {};
|
||||||
struct alignas(1) A1 { };
|
struct LLVM_ALIGNAS(2) A2 {};
|
||||||
struct alignas(2) A2 { };
|
struct LLVM_ALIGNAS(4) A4 {};
|
||||||
struct alignas(4) A4 { };
|
struct LLVM_ALIGNAS(8) A8 {};
|
||||||
struct alignas(8) A8 { };
|
|
||||||
#elif defined(__GNUC__)
|
|
||||||
struct A1 { } __attribute__((aligned(1)));
|
|
||||||
struct A2 { } __attribute__((aligned(2)));
|
|
||||||
struct A4 { } __attribute__((aligned(4)));
|
|
||||||
struct A8 { } __attribute__((aligned(8)));
|
|
||||||
#elif defined(_MSC_VER)
|
|
||||||
__declspec(align(1)) struct A1 { };
|
|
||||||
__declspec(align(2)) struct A2 { };
|
|
||||||
__declspec(align(4)) struct A4 { };
|
|
||||||
__declspec(align(8)) struct A8 { };
|
|
||||||
#else
|
|
||||||
# error No supported align as directive.
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct S1 {};
|
struct S1 {};
|
||||||
struct S2 { char a; };
|
struct S2 { char a; };
|
||||||
|
Loading…
x
Reference in New Issue
Block a user