[PATCH] D14337: Define a portable macro for specifying packed struct

David Li via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 4 12:58:08 PST 2015


davidxl updated this revision to Diff 39244.
davidxl added a comment.

Updated the patch with two more macros.

The first macro can not be used when we need to include a header file in the struct body (e.g, for common definitions). The START/END pair style can be used instead.

PTAL.


http://reviews.llvm.org/D14337

Files:
  include/llvm/Support/Compiler.h

Index: include/llvm/Support/Compiler.h
===================================================================
--- include/llvm/Support/Compiler.h
+++ include/llvm/Support/Compiler.h
@@ -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 
+# define LLVM_PACKED_END __attribute__((packed))
+#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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D14337.39244.patch
Type: text/x-patch
Size: 1094 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151104/541ae643/attachment.bin>


More information about the llvm-commits mailing list