<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Nov 4, 2015 at 8:18 PM, David Blaikie <span dir="ltr"><<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Nov 4, 2015 at 3:42 PM, Xinliang David Li via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: davidxl<br>
Date: Wed Nov  4 17:42:56 2015<br>
New Revision: 252099<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=252099&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=252099&view=rev</a><br>
Log:<br>
Define portable macros for packed struct definitions:<br>
<br>
 1. A macro with argument: LLVM_PACKED(StructDefinition)<br>
 2. A pair of macros defining scope of region with packing:<br>
    LLVM_PACKED_START<br>
     struct A { ... };<br>
     struct B { ... };<br>
    LLVM_PACKED_END<br></blockquote><div><br></div><div>What are we planning to use these for (I imagine there are already some uses of packed macros/etc in various parts of LLVM that this will be used to replace? What are they? What new uses do you have in mind?) I'm a little concerned, because this tend to leads to non-portable code trying to parse & then use structs with misaligned members, etc... (which, if I understand correctly, is only a perf penalty on X86, but potentially a correctness problem on other platforms we support/care about (not to mention the known bits stuff we do might assume certain bits are zero when they aren't, etc))</div><div> </div></div></div></div></blockquote><div><br></div><div>This is used for existing runtime data structure (Coverage Map's Function Record). Previously the structure is not explicitly declared but referenced with manually specified layout and alignment.</div><div><br></div><div>New uses of the macro should be done with care -- but there might be legit reason to use it though, let's not rule that out.</div><div><br></div><div>David</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Differential Revision: <a href="http://reviews.llvm.org/D14337" rel="noreferrer" target="_blank">http://reviews.llvm.org/D14337</a><br>
<br>
Modified:<br>
    llvm/trunk/include/llvm/Support/Compiler.h<br>
<br>
Modified: llvm/trunk/include/llvm/Support/Compiler.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/Compiler.h?rev=252099&r1=252098&r2=252099&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/Compiler.h?rev=252099&r1=252098&r2=252099&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/Support/Compiler.h (original)<br>
+++ llvm/trunk/include/llvm/Support/Compiler.h Wed Nov  4 17:42:56 2015<br>
@@ -293,6 +293,34 @@<br>
 # define LLVM_ALIGNAS(x) alignas(x)<br>
 #endif<br>
<br>
+/// \macro LLVM_PACKED<br>
+/// \brief Used to specify a packed structure.<br>
+/// LLVM_PACKED(<br>
+///    struct A {<br>
+///      int i;<br>
+///      int j;<br>
+///      int k;<br>
+///      long long l;<br>
+///   });<br>
+///<br>
+/// LLVM_PACKED_START<br>
+/// struct B {<br>
+///   int i;<br>
+///   int j;<br>
+///   int k;<br>
+///   long long l;<br>
+/// };<br>
+/// LLVM_PACKED_END<br>
+#ifdef _MSC_VER<br>
+# define LLVM_PACKED(d) __pragma(pack(push, 1)) d __pragma(pack(pop))<br>
+# define LLVM_PACKED_START __pragma(pack(push, 1))<br>
+# define LLVM_PACKED_END   __pragma(pack(pop))<br>
+#else<br>
+# define LLVM_PACKED(d) d __attribute__((packed))<br>
+# define LLVM_PACKED_START _Pragma("pack(push, 1)")<br>
+# define LLVM_PACKED_END   _Pragma("pack(pop)")<br>
+#endif<br>
+<br>
 /// \macro LLVM_PTR_SIZE<br>
 /// \brief A constant integer equivalent to the value of sizeof(void*).<br>
 /// Generally used in combination with LLVM_ALIGNAS or when doing computation in<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div></div>
</blockquote></div><br></div></div>