<div dir="ltr">Hi Thomas,<div><br></div><div>From what I know gcc is actually the one that's not correct here, a bigger alignment is considered stricter in C++ (though the Standard really should make this much clearer) since a lower alignment value results in more possible addresses, hence making the type's alignment weaker, and alignas is very explicitly forbidden from weakening alignment, especially the regular (unmodified) minimum alignment of said type. I don't know if there are places where we purposely weaken type alignment in HotSpot though</div><div><br></div><div>best regards,</div><div>Julian</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Mar 6, 2023 at 10:19 PM Thomas Stüfe <<a href="mailto:thomas.stuefe@gmail.com">thomas.stuefe@gmail.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"><div>Hi,</div><div><br></div><div>I'm not sure if this has been discussed before. With alignas, on clang, if the natural type of the data has a larger alignment than what I requested with alignas, I get a compile error if the specified alignment is smaller than what would be the natural alignment of the type.</div><div><br></div><div>Example:<br></div><br>struct alignas(2) XX {<br> void* p;<br>};<br><br>gives: error: requested alignment is less than minimum alignment of 8 for type 'XX'<br><br>Happens on both MacOS and Linux clang build. Does not happen with GCC. Does not happen with ATTRIBUTE_ALIGN(2).<br><br>Is this a clang bug? The standard [1] says:<br><br>"The object or the type declared by such a declaration will have its alignment requirement equal to the strictest (largest) non-zero expression of all alignas specifiers used in the declaration, unless it would weaken the natural alignment of the type. "<br><div><br></div><div>That reads to me like gcc is correct.<br></div><div><br></div>This is a bit of a drawback compared to ATTRIBUTE_ALIGN, especially if coding for different 32-bit and 64-bit platforms.<br><br>[1] <a href="https://en.cppreference.com/w/cpp/language/alignas" target="_blank">https://en.cppreference.com/w/cpp/language/alignas</a></div>
</blockquote></div>