[llvm] r233916 - [alignof] Put back the hack for old versions of GCC.
Benjamin Kramer
benny.kra at googlemail.com
Thu Apr 2 06:31:50 PDT 2015
Author: d0k
Date: Thu Apr 2 08:31:50 2015
New Revision: 233916
URL: http://llvm.org/viewvc/llvm-project?rev=233916&view=rev
Log:
[alignof] Put back the hack for old versions of GCC.
This works around a bug (PR56859) that is fixed in all versions of GCC I tested
with but was present in 4.8.0. Using 4.8.0 is of course a terrible idea, but looks
like we can't drop it just yet.
Modified:
llvm/trunk/include/llvm/Support/AlignOf.h
Modified: llvm/trunk/include/llvm/Support/AlignOf.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/AlignOf.h?rev=233916&r1=233915&r2=233916&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/AlignOf.h (original)
+++ llvm/trunk/include/llvm/Support/AlignOf.h Thu Apr 2 08:31:50 2015
@@ -70,11 +70,38 @@ inline unsigned alignOf() { return Align
// MSVC requires special handling here.
#ifndef _MSC_VER
+#if __has_feature(cxx_alignas)
template<std::size_t Alignment, std::size_t Size>
struct AlignedCharArray {
- LLVM_ALIGNAS(Alignment) char buffer[Size];
+ 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
/// \brief Create a type with an aligned char buffer.
More information about the llvm-commits
mailing list