<div dir="ltr"><div dir="ltr">


















<p class="MsoNormal" style="margin:0cm;font-family:"Times New Roman",serif"><font size="2"><span style="color:rgb(112,48,160)">It looks to me as if at least
examples 1, 2, and 4 are places that should <i>not</i> be changed to use the
"AIX preferred" alignment, because they are inquiring about the
guaranteed alignment of an existing pointer, which may well not have been
placed at the preferred alignment. I haven't dug into the code beyond your
snippet so I'm not sure about examples 3 and 5.<span></span></span></font></p>

<p class="MsoNormal" style="margin:0cm;font-family:"Times New Roman",serif"><font size="2"><span> </span></font></p>

<p class="MsoNormal" style="margin:0cm;font-family:"Times New Roman",serif"><font size="2">To be honest, I am not familiar with every snippet where
functions like “getTypeAlignInChars” is used. So I just list some locations
that call “getTypeAlignInChars”. But I did mean that we probably should replace
them with “PreferredAlignment” for AIX. <span></span></font></p>

<p class="MsoNormal" style="margin:0cm;font-family:"Times New Roman",serif"><font size="2"><span> </span></font></p>

<p class="MsoNormal" style="margin:0cm;font-family:"Times New Roman",serif"><font size="2">1. In AIX rules, not only an aggregate can now have a
different preferred alignment from guaranteed alignment, but also double, long
double.<span></span></font></p>

<p class="MsoNormal" style="margin:0cm;font-family:"Times New Roman",serif"><font size="2"><span> </span></font></p>

<p class="MsoNormal" style="margin:0cm;font-family:"Times New Roman",serif"><font size="2">We see the semantic of “PreferredAlignment” on AIX
represents a “T”’s<span class="gmail-im"> actual alignment. In other words, ABI alignment
on AIX is kinda useless except for being used to let “alignof(T)” return a
correct value. <span></span></span></font></p>

<p class="MsoNormal" style="margin:0cm;font-family:"Times New Roman",serif"><font size="2"><span class="gmail-im"><span> </span></span></font></p>

<p class="MsoNormal" style="margin:0cm;font-family:"Times New Roman",serif"><font size="2"><span class="gmail-im">2. For the example1, you mentioned the “</span><span style="color:rgb(112,48,160)">the guaranteed alignment of an existing pointer may well
not have been placed at the preferred alignment</span><span class="gmail-im">”. But as
I know, what function “getPreferredTypeAlign” does is to get the ABI/guaranteed
alignment of a “T” first by invoking “getTypeInfo”, and then minor adjust some values.
So we seems don’t need to worry about we cannot get a pointer’s ABI alignment,
and many other cases as well, if that’s the correct one for AIX.<span></span></span></font></p>

<p class="MsoNormal" style="margin:0cm;font-family:"Times New Roman",serif"><font size="2"><span class="gmail-im"><span> </span></span></font></p>

<p class="MsoNormal" style="margin:0cm;font-family:"Times New Roman",serif"><font size="2"><span class="gmail-im">Besides, I am not sure if I understand the
code snippet right in example1.<span></span></span></font></p>

<p class="MsoNormal" style="margin:0cm;font-family:"Times New Roman",serif"><font size="2"><span class="gmail-im"><span> </span></span></font></p>

<p class="MsoNormal" style="margin:0cm;font-family:"Times New Roman",serif"><font size="2"><span class="gmail-im"><span style="color:black;background:rgb(217,217,217) none repeat scroll 0% 0%">…</span><span style="background:rgb(217,217,217) none repeat scroll 0% 0%"><span></span></span></span></font></p>

<p class="MsoNormal" style="margin:0cm;font-family:"Times New Roman",serif"><font size="2"><span style="font-family:"Georgia",serif;color:black;background:rgb(217,217,217) none repeat scroll 0% 0%"> 
// If that failed, return the type's alignment.</span><span style="font-family:"Georgia",serif;background:rgb(217,217,217) none repeat scroll 0% 0%"><span></span></span></font></p>

<p class="MsoNormal" style="margin:0cm;font-family:"Times New Roman",serif"><font size="2"><span style="font-family:"Georgia",serif;color:black;background:rgb(217,217,217) none repeat scroll 0% 0%"> 
return S.Context.</span><span style="font-family:"Georgia",serif;color:rgb(197,90,17);background:rgb(217,217,217) none repeat scroll 0% 0%">getTypeAlignInChars</span><span style="font-family:"Georgia",serif;color:black;background:rgb(217,217,217) none repeat scroll 0% 0%">(E->getType()->getPointeeType());</span><span style="font-family:"Georgia",serif;background:rgb(217,217,217) none repeat scroll 0% 0%"><span></span></span></font></p>

<p class="MsoNormal" style="margin:0cm;font-family:"Times New Roman",serif"><font size="2"><span style="font-family:"Georgia",serif;color:black;background:rgb(217,217,217) none repeat scroll 0% 0%">}</span><span style="font-family:"Georgia",serif;background:rgb(217,217,217) none repeat scroll 0% 0%"><span></span></span></font></p>

<p class="MsoNormal" style="margin:0cm;font-family:"Times New Roman",serif"><font size="2"><span style="font-family:"Georgia",serif;color:black;background:rgb(217,217,217) none repeat scroll 0% 0%">…</span><span style="font-family:"Georgia",serif;background:rgb(217,217,217) none repeat scroll 0% 0%"><span></span></span></font></p>

<p class="MsoNormal" style="margin:0cm;font-family:"Times New Roman",serif"><font size="2"><span style="font-family:"Georgia",serif;background:rgb(217,217,217) none repeat scroll 0% 0%"><span> </span></span></font></p>

<p class="MsoNormal" style="margin:0cm;font-family:"Times New Roman",serif"><font size="2"><span style="font-family:"Georgia",serif">A pointer’s
pointeeType can be anything, which may be an aggregate, <span> </span>double, or long doble etc. For those types, on
AIX, we do need to get the “PreferredAlignment”?<span></span></span></font></p>

<p class="MsoNormal" style="margin:0cm;font-family:"Times New Roman",serif"><font size="2"><span style="font-family:"Georgia",serif"><span> </span></span></font></p>

<p class="MsoNormal" style="margin:0cm;font-family:"Times New Roman",serif"><font size="2"><span style="font-family:"Georgia",serif">3. So far, I didn’t
investigate every usage of those four functions:<span></span></span></font></p>

<p class="MsoNormal" style="margin:0cm;font-family:"Times New Roman",serif"><font size="2"><span>1) getTypeAlignInChars [invokes getTypeAlign]<span></span></span></font></p>

<p class="MsoNormal" style="margin:0cm;font-family:"Times New Roman",serif"><font size="2"><span>2) getTypeAlign <=> getTypeInfo(T).<a href="https://clang.llvm.org/doxygen/structclang_1_1TypeInfo.html#af98dcefc364629eff868a1bb4010ebd8" style="color:rgb(5,99,193);text-decoration:underline">Align</a><span></span></span></font></p>

<p class="MsoNormal" style="margin:0cm;font-family:"Times New Roman",serif"><font size="2"><span>3) getTypeInfo [ invokes ‘getTypeInfoImpl’]<span></span></span></font></p>

<p class="MsoNormal" style="margin:0cm;font-family:"Times New Roman",serif"><font size="2"><span>4) getTypeInfoInChars<span></span></span></font></p>

<p class="MsoNormal" style="margin:0cm;font-family:"Times New Roman",serif"><font size="2"><span><span> </span></span></font></p>

<p class="MsoNormal" style="margin:0cm;font-family:"Times New Roman",serif"><font size="2"><span>Because I am not sure if we really want to spend a lot of time
on digging each crack</span><span lang="EN-US">. An
initial scan of them shows a large amount of them used in Clang. How do you
think about this?<span></span></span></font></p>

<p class="MsoNormal" style="margin:0cm;font-family:"Times New Roman",serif"><font size="2"><span lang="EN-US"><span> </span></span></font></p>

<p class="MsoNormal" style="margin:0cm;font-family:"Times New Roman",serif"><font size="2"><span lang="EN-US"><span> </span></span></font></p>

<p class="MsoNormal" style="margin:0cm;font-family:"Times New Roman",serif"><font size="2"><span lang="EN-US">And most
importantly, besides of “adding a flag” way to handle speical alignment on AIX,
I am wondering in which way we can handle it better?<span></span></span></font></p>

<p class="MsoNormal" style="margin:0cm;font-family:"Times New Roman",serif"><font size="2"><span lang="EN-US"><span> </span></span></font></p>

<p class="MsoNormal" style="margin:0cm;font-family:"Times New Roman",serif"><font size="2"><span lang="EN-US"><span> </span></span></font></p>

<font size="2">Regards,</font></div><div><font size="2">Xiangling<br></font></div><div dir="ltr">

<p class="MsoNormal" style="margin:0cm;font-family:"Times New Roman",serif"><font size="2"><span class="gmail-im"><span> </span></span></font></p>

<p class="MsoNormal" style="margin:0cm;font-family:"Times New Roman",serif"><font size="2"><span class="gmail-im"><span> </span></span></font></p>

<p class="MsoNormal" style="margin:0cm;font-family:"Times New Roman",serif"><font size="2"><span> </span></font></p>

<p class="MsoNormal" style="margin:0cm;font-family:"Times New Roman",serif"><font size="2"><span> </span></font></p>

<p class="MsoNormal" style="margin:0cm;font-family:"Times New Roman",serif"><font size="2"><span> </span></font></p>

<p class="MsoNormal" style="margin:0cm;font-family:"Times New Roman",serif"><font size="2"><span> </span></font></p>





</div><div dir="ltr"><font size="2"><br></font></div><font size="2"><br></font><div class="gmail_quote"><div dir="ltr" class="gmail_attr"><font size="2">On Tue, Aug 18, 2020 at 8:48 AM James Y Knight <<a href="mailto:jyknight@google.com" target="_blank">jyknight@google.com</a>> wrote:<br></font></div><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"><div><font size="2"><br><br></font><div class="gmail_quote"><div dir="ltr" class="gmail_attr"><font size="2">On Tue, Aug 18, 2020, 12:54 AM David Rector <<a href="mailto:davrecthreads@gmail.com" target="_blank">davrecthreads@gmail.com</a>> wrote:<br></font></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div style="margin:0px;font-stretch:normal;line-height:normal"><font size="2">I would have to think that, whatever the documentation for  e.g. <span style="font-stretch:normal;line-height:normal;font-family:Menlo">getTypeAlignInChars(T)</span>, most users expect it to return T’s actual alignment for their target, whether it was determined from the ABI, or the AIX alignment scheme, or whatever.<br></font></div></div></blockquote></div></div><div dir="auto"><font size="2"><br></font></div><div dir="auto"><font size="2">There really are two concepts at play here.</font></div><div dir="auto"><font size="2"><br></font></div><div dir="auto"><font size="2">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?)</font></div><div dir="auto"><font size="2"><br></font></div><div dir="auto"><font size="2">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.</font></div><div dir="auto"><font size="2"><br></font></div><div dir="auto"><font size="2">AIX is not the first platform where these alignments differ -- the type 'double' on x86-32 being the other notable example. But, the AIX rules trigger differences in more circumstances than we've had before, and thus we now need to potentially make a choice in other parts of the code. Importantly: in AIX rules, an aggregate can now have a different preferred alignment from guaranteed alignment, too.</font></div><div dir="auto"><font size="2"><br></font></div><div dir="auto"><font size="2">The first case brought up where this surely matters, is 'new T[100]' where T has a destructor. This thread is exploring whether there are other such cases that we might need to change, too. I suspect that there are not many, but that remains to be determined.</font></div><div dir="auto"><font size="2"><br></font></div><div dir="auto"><font size="2"><br></font></div><div dir="auto"><font size="2"><br></font></div><div dir="auto"><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><div><div style="margin:0px;font-stretch:normal;line-height:normal;min-height:14px"><font size="2"><br></font></div><div style="margin:0px;font-stretch:normal;line-height:normal"><font size="2">In fact, maybe we can go further: I would think that any valid use of type alignment which explicitly ignores AIX or other target-specific alignment schemes are probably just implementation details used only in the calculation of some composed type’s alignment under that scheme.  In other words I would assume every function call in which AIX preferred alignment needed to be ignored is in the some layout-building implementation — is that right?</font></div><div style="margin:0px;font-stretch:normal;line-height:normal;min-height:14px"><font size="2"><br></font></div><div style="margin:0px;font-stretch:normal;line-height:normal"><font size="2">E.g. the lib/AST/RecordLayoutBuilder.</font><font size="2">cpp example you cite below fits this description — in <span style="font-stretch:normal;line-height:normal;font-family:Menlo">LayoutField(FieldDecl *D, …)</span> you propose to change the call to fetch the ABI/non-AIX type info via </font></div><div style="margin:0px;font-stretch:normal;line-height:normal"><font size="2" face="Menlo">getTypeInfo(D->getType(), true/* NeedsABIAlignment */);</font></div><div style="margin:0px;font-stretch:normal;line-height:normal"><font size="2">but only so that you can later tweak that info whenever <span style="font-stretch:normal;line-height:normal;font-family:Menlo;color:rgb(27,31,34);background-color:rgb(255,255,255)">DefaultsToAIXPowerAlignment==true</span>. </font></div><div style="margin:0px;font-stretch:normal;line-height:normal;min-height:14px"><font size="2"><br></font></div><div style="margin:0px;font-stretch:normal;line-height:normal"><font size="2">If all the changes you would need to make are indeed similar to this, these expanded usages are really only implementation details needed to build type layouts, and thus the goal should simply be to sufficiently hide these details from common programmers who don’t need to build type layouts, only access them.</font></div><div style="margin:0px;font-stretch:normal;line-height:normal;min-height:14px"><font size="2"><br></font></div><div style="margin:0px;font-stretch:normal;line-height:normal"><font size="2">I think your original option #2 ("add a flag"), i.e. adding new defaulted parameters to a few functions, seems to be a reasonable way to hide these new details, so long as the new parameters are well named and documented.  It also seems sufficiently general to be useful for implementing other special default alignment schemes in the future.</font></div><div style="margin:0px;font-stretch:normal;line-height:normal;min-height:14px"><font size="2"><br></font></div><div style="margin:0px;font-stretch:normal;line-height:normal"><font size="2">Dave</font></div></div><font size="2"><br></font></div></blockquote></div></div></div>
</blockquote></div>
</div>