[cfe-dev] [RFC] Adding AIX power alignment rule in clang front end

Hubert Tong via cfe-dev cfe-dev at lists.llvm.org
Sun Apr 26 08:35:22 PDT 2020


On Sun, Apr 26, 2020 at 10:23 AM James Y Knight <jyknight at google.com> wrote:

> Unfortunately, this is invalid behavior. _Alignof/alignof must return the
> *required* alignment for a type. Given that per your previous example:
> struct C {
>   int n;
>   struct A a;
> };
> would place the type A at an offset of 4, alignof(A) cannot correctly
> return greater than 4.
>
I am inclined to agree. There are practical effects on the return value of
such queries for user programs such as problems with PointerIntPair-like
mechanisms and the minimally-guaranteed alignment barring contortions is
the safe value. I'm not sure if we will eventually need a further extension
(under option control) to make the return value match the reference
implementations.


>
> You also need to ensure that the alignment values that Clang specifies
> when creating memory operations in LLVM IR are correct, and not higher than
> they should be, which they will be, if you've set the alignment of the
> structure too high.
>
If a user wishes to operate on an under-aligned object with Clang, what is
the recommendation? I am asking mainly in terms of the user source.


>
> I believe the best option would be to modify the struct layout code to
> round up the size as Eli suggests, and then modify
> ASTContext::getPreferredTypeAlign so that variables of these types get an
> increased alignment. This function is also used to implement the
> non-standard GCC extension "__alignof__(T)", which unlike alignof/_Alignof,
> returns the "preferred" alignment of T, rather than the minimum alignment.
>
Thanks. I think we can explore that.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20200426/8fe7d229/attachment.html>


More information about the cfe-dev mailing list