<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div style="margin: 0px; font-stretch: normal; line-height: normal;" class="">For that matter "preferred alignment" is also confusing.  Who prefers it?  When might that preference not be met?</div><div style="margin: 0px; font-stretch: normal; line-height: normal; min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class="">Here is my full understanding so far, expressed in the hope that pointing out my confusions here might better help answer Xiangling’s questions below:</div>
<ul class="">
<li style="margin: 0px; font-stretch: normal; line-height: normal;" class=""> The "ABI" alignment of a type = the ABI-guaranteed minimum alignment of any object of that type built by any standard-conformant compiler.</li>
<li style="margin: 0px; font-stretch: normal; line-height: normal;" class="">The "preferred" alignment of a type = the actual alignment, at least as large as the ABI alignment, that <i class="">our</i> compiler will <i class="">always</i> use in constructing an object of that type.</li>
<li style="margin: 0px; font-stretch: normal; line-height: normal;" class="">Therefore, whenever we are dealing with an object we know <i class="">our</i> compiler has constructed, we can use the "preferred" alignment.</li><ul class=""><li style="margin: 0px; font-stretch: normal; line-height: normal;" class="">And thereby take advantage of target-specific optimizations like AIX.</li></ul>
<li style="margin: 0px; font-stretch: normal; line-height: normal;" class="">However, whenever we are dealing with e.g. a pointer to an object we are not sure we built — i.e. which may have been constructed within a function not compiled by our compiler (e.g. a function compiled without AIX in some library might have constructed that object and passed a pointer to it to some function our compiler is presently building) -- we are forced to use only the ABI-guaranteed minimum alignment.</li><ul class=""><li style="margin: 0px; font-stretch: normal; line-height: normal;" class="">`-And thereby miss out on AIX.</li></ul><li style="margin: 0px; font-stretch: normal; line-height: normal;" class="">Whenever a type has <font face="Menlo" class="">alignas(N)</font>, that alignment will be returned for…both the ABI and the preferred alignments?  It will override both?  Is that right?  I recall it overrides the preferred alignment in Xiangling’s implementation, at least, not sure about the ABI case.</li><li style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><font face="Menlo" class="">alignof(T)</font> / <font face="Menlo" class="">__alignof(T)</font> must return the "ABI" and "preferred" alignments of <font face="Menlo" class="">T</font>, respectively.</li></ul><div class="">And here are Xiangling’s responses/new questions reproduced again, to get back to the specifics:</div><div class=""><br class=""></div><div class=""><blockquote type="cite" class=""><div dir="ltr" class=""><div class="" style="margin: 0cm; font-size: 12pt; font-family: "Times New Roman", serif;"><span class="" style="color: rgb(112, 48, 160);">1. Given a pointer to some object of type T or a field of type T inside another object, what can I know for sure about the alignment of that pointer? (How many of the low bits are absolutely guaranteed to be 0, assuming the program doesn't involve Undefined Behavior?)<span class=""></span></span></div><p class="MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: "Times New Roman", serif;"><span class="" style="color: rgb(112, 48, 160);"> </span></p><div class="" style="margin: 0cm; font-size: 12pt; font-family: "Times New Roman", serif;">“<i class="">what can I know for sure about the alignment of that pointer</i>” I assume you mean “<i class="">the alignment of the pointee</i>”. So this means we should always use ABI alignment for the pointee, because it’s an unknown object for the compiler right? <span class=""></span></div><p class="MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: "Times New Roman", serif;"><span class=""> </span></p><div class="" style="margin: 0cm; font-size: 12pt; font-family: "Times New Roman", serif;">Besides that, any other scenarios you are aware of that we should always use ABI alignment?<span class=""></span></div><p class="MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: "Times New Roman", serif;"><span class=""> </span></p><div class="" style="margin: 0cm; font-size: 12pt; font-family: "Times New Roman", serif;"><span class="" style="color: rgb(112, 48, 160);">2. If I want to allocate a brand new complete object of type T, at what alignment should I use to place it? This must be at least the alignment from 1. But beyond that, it could differ by circumstance, e.g. stack, global, and function parameter allocations could make different choices. In some cases, increasing the alignment of an allocation above the required minimum may just be an optimization, but in other cases it has an ABI impact.<span class=""></span></span></div><p class="MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: "Times New Roman", serif;"><span class=""> </span></p><div class="" style="margin: 0cm; font-size: 12pt; font-family: "Times New Roman", serif;">Does this mean when we <i class="">“allocate a brand new complete object of type T”, </i>we will prioritize/take “PreferredAlignment”?<span class=""></span></div><p class="MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: "Times New Roman", serif;"><span class=""> </span></p><p class="MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: "Times New Roman", serif;"><span class=""> </span></p><div class="" style="margin: 0cm; font-size: 12pt; font-family: "Times New Roman", serif;"><span lang="EN-US" class="">Regarding X86-32, can you show me an example of how X86-32 makes the choice between PreferredAlignment and ABI alignment for “double” type? <span class=""></span></span></div><p class="MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: "Times New Roman", serif;"><span lang="EN-US" class=""> </span></p><div class="" style="margin: 0cm; font-size: 12pt; font-family: "Times New Roman", serif;"><span lang="EN-US" class="">Thank you,</span></div><div class="" style="margin: 0cm; font-size: 12pt; font-family: "Times New Roman", serif;"><span lang="EN-US" class="">Xiangling</span></div></div></blockquote><br class=""></div><div class=""><br class=""></div><div><br class=""><blockquote type="cite" class=""><div class="">On Aug 19, 2020, at 6:07 PM, James Y Knight via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org" class="">cfe-dev@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div dir="ltr" class="">On Wed, Aug 19, 2020 at 5:57 PM Richard Smith <<a href="mailto:richard@metafoo.co.uk" class="">richard@metafoo.co.uk</a>> wrote:<br class=""></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr" class=""><div dir="ltr" class="">On Wed, 19 Aug 2020 at 12:16, James Y Knight via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org" target="_blank" class="">cfe-dev@lists.llvm.org</a>> wrote:<br class=""></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto" class=""><div class=""><span style="font-family:sans-serif" class="">I wasn't talking about the alignment of a pointer, but rather the alignment of a value of type 'double', which has a preferred alignment of 8.</span></div><div dir="auto" class=""><span style="font-family:sans-serif" class=""><br class=""></span></div><div dir="auto" class=""><span style="font-family:sans-serif" class="">Not all double values in memory are 8 byte aligned -- some are placed only at 4 byte aligned offsets. Therefore, the compiler can only assume an alignment of 4 for an unknown object of type 'double' -- this is the abi alignment.</span></div></div></blockquote><div class=""><br class=""></div><div class="">It seems to me that the term "ABI alignment" is actively confusing matters here -- both alignment values are part of the ABI in the AIX case. Perhaps "minimum alignment" would be a better term for the alignment that all objects of the type are guaranteed to have?</div><div class=""></div></div></div></blockquote><div class=""><br class=""></div><div class="">I agree that "ABI alignment" is a poor name. I like calling it "guaranteed type alignment".</div></div></div>
_______________________________________________<br class="">cfe-dev mailing list<br class=""><a href="mailto:cfe-dev@lists.llvm.org" class="">cfe-dev@lists.llvm.org</a><br class="">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev<br class=""></div></blockquote></div><br class=""></body></html>