https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126304
Bug ID: 126304
Summary: AIX with -malign-power (default): leading double
member limits alignment for entire union to 4
Product: gcc
Version: 15.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: paul.groke at dynatrace dot com
Target Milestone: ---
I'm aware that there's special rules for `double` and `long double` in the
"power" alignment mode: struct members of those types only receive alignment 4
in most cases. However it is my understanding that this only applies to the
(long) double member itself, and should not apply to things like other members
of a union.
Specifically, I would expect the union in the following struct to be aligned to
8 bytes in 64 bit mode:
struct Foo {
char c;
union {
double ud;
void* uptr;
};
};
However GCC aligns the entire union to 4 if the first union member is a double.
Example (compile as 64 bit):
```
#include <stdio.h>
#include <stddef.h>
struct Bad {
char c;
union {
double ud;
void* uptr;
};
};
struct Good1 {
char c;
union {
void* uptr;
double ud;
};
};
struct Good2 {
char c;
union {
int ui;
double ud;
void* uptr;
};
};
int main() {
printf("Bad: %zu\n", offsetof(struct Bad, uptr)); // 4 (expected 8)
printf("Good1: %zu\n", offsetof(struct Good1, uptr)); // 8
printf("Good2: %zu\n", offsetof(struct Good2, uptr)); // 8
}
```
Curiously this only seems to happen when compiling on AIX. I was not able to
reproduce it when compiling on Linux/PPC with `-malign-power`.
I was not able to compare against XL C since I don't have access. I'd be
grateful if someone could test this with XL C, maybe even with XL C versions
before and after the switch to Clang.