summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorReid Kleckner <reid@kleckner.net>2015-04-02 17:43:35 +0000
committerReid Kleckner <reid@kleckner.net>2015-04-02 17:43:35 +0000
commitf1a6414b49778a108751be15779d6639bf1e5486 (patch)
tree2f0aa30df60ccb6b77c755dbe92f7946c19a0a57
parent03dc366e79cd01afe0bbfad2a7ede3087d6c9356 (diff)
downloadbcm5719-llvm-f1a6414b49778a108751be15779d6639bf1e5486.tar.gz
bcm5719-llvm-f1a6414b49778a108751be15779d6639bf1e5486.zip
Add an LLVM_PTR_SIZE macro to make LLVM_ALIGNAS more useful
MSVC 2013 requires the argument to __declspec(align()) to be an integer constant expression that doesn't involve any identifiers like sizeof. For GCC and Clang, LLVM_PTR_SIZE is equivalent to __SIZEOF_POINTER__, which dates back to GCC 4.6 and Clang 2010. If that's not available, we get sizeof(void*), which works with alignas() and __attribute__((aligned())). For MSVC, LLVM_PTR_SIZE is 4 or 8 depending on _WIN64. llvm-svn: 233929
-rw-r--r--llvm/include/llvm/Support/Compiler.h19
1 files changed, 18 insertions, 1 deletions
diff --git a/llvm/include/llvm/Support/Compiler.h b/llvm/include/llvm/Support/Compiler.h
index 1a49956e225..8534316600a 100644
--- a/llvm/include/llvm/Support/Compiler.h
+++ b/llvm/include/llvm/Support/Compiler.h
@@ -283,7 +283,8 @@
/// \macro LLVM_ALIGNAS
/// \brief Used to specify a minimum alignment for a structure or variable. The
-/// alignment must be a constant integer.
+/// alignment must be a constant integer. Use LLVM_PTR_SIZE to compute
+/// alignments in terms of the size of a pointer.
///
/// Note that __declspec(align) has special quirks, it's not legal to pass a
/// structure with __declspec(align) as a formal parameter.
@@ -295,6 +296,22 @@
# define LLVM_ALIGNAS(x) alignas(x)
#endif
+/// \macro LLVM_PTR_SIZE
+/// \brief A constant integer equivalent to the value of sizeof(void*).
+/// Generally used in combination with LLVM_ALIGNAS or when doing computation in
+/// the preprocessor.
+#ifdef __SIZEOF_POINTER__
+# define LLVM_PTR_SIZE __SIZEOF_POINTER__
+#elif defined(_WIN64)
+# define LLVM_PTR_SIZE 8
+#elif defined(_WIN32)
+# define LLVM_PTR_SIZE 4
+#elif defined(_MSC_VER)
+# error "could not determine LLVM_PTR_SIZE as a constant int for MSVC"
+#else
+# define LLVM_PTR_SIZE sizeof(void *)
+#endif
+
/// \macro LLVM_FUNCTION_NAME
/// \brief Expands to __func__ on compilers which support it. Otherwise,
/// expands to a compiler-dependent replacement.
OpenPOWER on IntegriCloud