<div dir="ltr"><div dir="ltr">(And while I did initially also express skepticism about whether this feature is necessary at all -- even if properly implemented -- I think the fact that Intel, Apple, and Sony have all proposed or implemented something along these lines is good evidence that it is sufficiently useful. I'm convinced on that point!)</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Apr 19, 2021 at 2:30 PM James Y Knight <<a href="mailto:jyknight@google.com">jyknight@google.com</a>> wrote:<br></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="ltr"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>I understand your goal is to find and fix bugs in software that is<br>still under development and CAN be fixed.  I fully endorse that<br>goal.  However, that is not the situation that Sony has, and likely<br>not what Intel has.  Your proposal will NOT solve our problem.</blockquote><div></div><div><div class="gmail_quote"><div dir="ltr" class="gmail_attr"><br></div><div class="gmail_attr">No, that's not it at all! I'm afraid you've totally misunderstood my concern.</div><div class="gmail_attr"><br></div><div class="gmail_attr">My goal is that if we add a compiler feature to address this problem -- so that you can compile code with under-aligned objects, and have it work as the author expected it to --  that the feature <i>reliably </i>addresses the problem, and makes such code no longer exhibit Undefined Behavior. The proposed backend change does not accomplish that, but we can implement a feature which will.</div><div class="gmail_attr"><br></div><div class="gmail_attr">As Reid said, -fmax-type-align=N appears to be <i>almost</i> that feature, and something like this little patch (along with documentation update) may be all that's needed (but this is totally untested).</div><div dir="ltr" class="gmail_attr"><div><font face="monospace"><br></font></div><div><font face="monospace">diff --git clang/lib/CodeGen/CodeGenModule.cpp clang/lib/CodeGen/CodeGenModule.cpp<br>index b23d995683bf..3aef166a690e 100644<br>--- clang/lib/CodeGen/CodeGenModule.cpp<br>+++ clang/lib/CodeGen/CodeGenModule.cpp<br>@@ -6280,8 +6280,7 @@ CharUnits CodeGenModule::getNaturalTypeAlignment(QualType T,<br>   // Cap to the global maximum type alignment unless the alignment<br>   // was somehow explicit on the type.<br>   if (unsigned MaxAlign = getLangOpts().MaxTypeAlign) {<br>-    if (Alignment.getQuantity() > MaxAlign &&<br>-        !getContext().isAlignmentRequired(T))<br>+    if (Alignment.getQuantity() > MaxAlign)<br>       Alignment = CharUnits::fromQuantity(MaxAlign);<br>   }<br>   return Alignment;</font><br></div><div><br></div></div></div></div></div>
</blockquote></div></div>