[llvm] r252099 - Define portable macros for packed struct definitions:

Xinliang David Li via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 4 15:42:56 PST 2015


Author: davidxl
Date: Wed Nov  4 17:42:56 2015
New Revision: 252099

URL: http://llvm.org/viewvc/llvm-project?rev=252099&view=rev
Log:
Define portable macros for packed struct definitions:

 1. A macro with argument: LLVM_PACKED(StructDefinition)
 2. A pair of macros defining scope of region with packing:
    LLVM_PACKED_START
     struct A { ... };
     struct B { ... };
    LLVM_PACKED_END

Differential Revision: http://reviews.llvm.org/D14337

Modified:
    llvm/trunk/include/llvm/Support/Compiler.h

Modified: llvm/trunk/include/llvm/Support/Compiler.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/Compiler.h?rev=252099&r1=252098&r2=252099&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/Compiler.h (original)
+++ llvm/trunk/include/llvm/Support/Compiler.h Wed Nov  4 17:42:56 2015
@@ -293,6 +293,34 @@
 # define LLVM_ALIGNAS(x) alignas(x)
 #endif
 
+/// \macro LLVM_PACKED
+/// \brief Used to specify a packed structure.
+/// LLVM_PACKED(
+///    struct A {
+///      int i;
+///      int j;
+///      int k;
+///      long long l;
+///   });
+///
+/// LLVM_PACKED_START
+/// struct B {
+///   int i;
+///   int j;
+///   int k;
+///   long long l;
+/// };
+/// LLVM_PACKED_END 
+#ifdef _MSC_VER
+# define LLVM_PACKED(d) __pragma(pack(push, 1)) d __pragma(pack(pop))
+# define LLVM_PACKED_START __pragma(pack(push, 1))
+# define LLVM_PACKED_END   __pragma(pack(pop))
+#else
+# define LLVM_PACKED(d) d __attribute__((packed))
+# define LLVM_PACKED_START _Pragma("pack(push, 1)")
+# define LLVM_PACKED_END   _Pragma("pack(pop)")
+#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




More information about the llvm-commits mailing list