https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126338
Bug ID: 126338
Summary: Array of atomic structs has smaller alignment than its
elements
Product: gcc
Version: 16.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: tellowkrinkle at gmail dot com
Target Milestone: ---
In the following code, on a 64-bit platform, `struct One` has 16-byte
alignment, while `struct Two` has 8-byte alignment. Getting a pointer to
`Two::yay[0]` would therefore be misaligned for its `_Atomic struct Yay` type.
```
struct Yay {
void *a;
void *b;
};
struct One {
_Atomic struct Yay yay;
};
struct Two {
_Atomic struct Yay yay[1];
};
unsigned OneAlign() {
return _Alignof(struct One);
}
unsigned TwoAlign() {
return _Alignof(struct Two);
}
```
Godbolt link: https://gcc.godbolt.org/z/c3M8vvPhf