<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Jul 23, 2014 at 10:18 AM, Erik Schwiebert <span dir="ltr"><<a href="mailto:eriksc@microsoft.com" target="_blank">eriksc@microsoft.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">



<div style="word-wrap:break-word">
Would it be possible to have clang support the alignas inside a pragma pack directive, if the structure in question is also inside a pragma ms_struct directive?  There are some teams at Microsoft using clang to target non-Windows platforms but sharing code
 that expects MSVC structure layout.  Using the Microsoft C++ ABI isn’t feasible as the platform in question is not a Microsoft Windows platform.  </div></blockquote><div><br></div><div>Our documentation says:</div><div>
<br></div><div><div>"clang supports the Microsoft #pragma pack feature for controlling record layout. GCC also contains support for this feature, however where MSVC and GCC are incompatible clang follows the MSVC definition."</div>
</div><div><br></div><div>... so I think we should do the obviously sane thing here in all cases (that is, alignas on a field should beat #pragma pack).</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div style="word-wrap:break-word">
<div>Thanks,</div>
<div>Schwieb</div>
<div>Microsoft Mac Team<br>
<div><br>
<div><div><div class="h5">
<div>On Jul 23, 2014, at 9:48 AM, jahanian <<a href="mailto:fjahanian@apple.com" target="_blank">fjahanian@apple.com</a>> wrote:</div>
<br>
</div></div><blockquote type="cite"><div><div class="h5">
<div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">

<div><br>
On Jul 23, 2014, at 9:45 AM, jahanian <<a href="mailto:fjahanian@apple.com" target="_blank">fjahanian@apple.com</a>> wrote:</div>
<br>
<blockquote type="cite">
<div style="word-wrap:break-word">
<br>
<div>
<div>On Jul 22, 2014, at 5:26 PM, Reid Kleckner <<a href="mailto:rnk@google.com" target="_blank">rnk@google.com</a>> wrote:</div>
<br>
<blockquote type="cite">
<div dir="ltr">
<div class="gmail_extra">
<div class="gmail_quote"><br>
<div><br>
</div>
<div>Presumably they handle alignas the same way they handle __declspec(align(N)), which overrides packing.  MSVC appears to have two notions of alignment, required and advisory, while the C++ standard, Clang, and GCC only have one.  One way to observe this
 is to see that they will align an int64 to 8 bytes in a struct, but they will not realign the stack to 8 bytes when that struct is stack allocated.</div>
<div><br>
</div>
<div>Also, Clang does respect alignas in this case when targeting the Microsoft C++ ABI.</div>
</div>
</div>
</div>
</blockquote>
<br>
</div>
<div>I tried the test case with these options for MS ABI:</div>
<div><br>
</div>
<div>
<div style="margin:0px;font-size:11px;font-family:Menlo">clang -cc1 -triple x86_64-windows-msvc -std=c++11 -S t.cpp</div>
<div style="margin:0px;font-size:11px;font-family:Menlo"><br>
</div>
<div style="margin:0px;font-size:11px;font-family:Menlo">Assembly indicates that it does not seem to respect alignas. Should I be using other options?</div>
<div style="margin:0px;font-size:11px;font-family:Menlo"><br>
</div>
<div style="margin:0px;font-size:11px;font-family:Menlo">
<div style="margin:0px">main:</div>
<div style="margin:0px"><span style="white-space:pre-wrap"></span>movl<span style="white-space:pre-wrap">
</span>$28, %eax</div>
<div style="margin:0px"><span style="white-space:pre-wrap"></span>movl<span style="white-space:pre-wrap">
</span>$0, -4(%rsp)</div>
<div style="margin:0px"><span style="white-space:pre-wrap"></span>retq</div>
<div><br>
</div>
<div><br>
</div>
</div>
</div>
</div>
</blockquote>
<div><br>
</div>
Oops. I was using an old clang. Sorry for the noise.</div>
<div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">

<br>
</div>
<div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">

<div style="margin:0px;font-size:11px;font-family:Menlo">main:</div>
<div style="margin:0px;font-size:11px;font-family:Menlo"><span style="white-space:pre-wrap"></span>movl<span style="white-space:pre-wrap">
</span>$64, %eax</div>
<div style="margin:0px;font-size:11px;font-family:Menlo"><span style="white-space:pre-wrap"></span>retq</div>
<div style="margin:0px;font-size:11px;font-family:Menlo"><br>
</div>
<blockquote type="cite">
<div style="word-wrap:break-word">
<div>
<div style="margin:0px;font-size:11px;font-family:Menlo">
<div>- Fariborz</div>
<div><br>
</div>
</div>
</div>
<br>
</div>
</blockquote>
</div>
<br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">

</div></div><div class=""><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">_______________________________________________</span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">

<span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">cfe-dev
 mailing list</span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">

<a href="mailto:cfe-dev@cs.uiuc.edu" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" target="_blank">cfe-dev@cs.uiuc.edu</a><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">

<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a></div>
</blockquote>
</div>
<br>
</div>
</div>
</div>

</blockquote></div><br></div></div>