RFR: 7904115: Fix for AIX test case failures due to incorrect alignment for double and pointer [v2]
Jorn Vernee
jvernee at openjdk.org
Fri Nov 21 14:08:47 UTC 2025
On Fri, 21 Nov 2025 13:06:50 GMT, Jorn Vernee <jvernee at openjdk.org> wrote:
>> Yes, that's expected, but I think the test should be modified to handle that instead. The issue with the code in this patch is that it adjusts the alignment down to `4` in some cases when the requested alignment is `8`. The requested alignment (i.e. the `align` argument) is always correct here, since that is what we get straight from clang based on alignment specifiers or pack pragmas.
>>
>> For instance, for a struct like this:
>>
>>
>> struct foo {
>> alignas(8) double d;
>> };
>>
>>
>> `align` would be `8` here for the field `d`, but you overwrite it to `4`, which doesn't seem right.
>
> Okay, I had another look at the test, and it looks like it can not really be adjusted, so there might be an issue elsewhere.
I did a little debugging, and it looks like clang doesn't attach the alignment specified by `alignas` to the field declaration any ways. So, we can not handle hyper-aligned fields even if we wanted to. In other words, you can disregard the example above.
On the other hand, I'm not sure if clang attaches the right alignment to double fields that are not the first field on AIX. Look at the code in `StructBuilder` that generates the layouts for fields:
if (member instanceof Variable var) {
memberLayout = layoutString(var.type(), align);
memberLayout = String.format("%1$s%2$s.withName("%3$s")", indentString(indent + 1), memberLayout, member.name());
}
You should be able to get the alignment of the field deceleration using `long fieldAlign = ClangAlignOf.getOrThrow(var) / 8;`. If this is `4` as expected for a non-first double field, then we could just pass that information down to the code that generates the layout string, I think.
-------------
PR Review Comment: https://git.openjdk.org/jextract/pull/296#discussion_r2549869717
More information about the jextract-dev
mailing list