https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94081
Matthew Lugg <mlugg at mlugg dot co.uk> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |mlugg at mlugg dot co.uk
--- Comment #1 from Matthew Lugg <mlugg at mlugg dot co.uk> ---
I have also hit this issue---I have some generated C code which triggers
thousands of '-Waddress-of-packed-member' warnings, all of which are false
positives due to '_Alignas' annotations. Rather than a local variable, my repro
embeds the packed type in an explicitly-aligned field of a different type:
union foo {
int a;
} __attribute__((packed));
struct bar {
_Alignas(8) union foo payload;
};
int *get_inner(struct bar *ptr) {
return &ptr->payload.a;
}
The output of 'gcc -c source.c' with GCC 15.2 is:
source.c: In function 'get_inner':
source.c:8:12: warning: taking address of packed member of 'union foo' may
result in an unaligned pointer value [-Waddress-of-packed-member]
8 | return &ptr->payload.a;
| ^~~~~~~~~~~~~~~
For comparison, Clang (correctly) compiles this code without warnings all the
way back to when they first introduced '-Waddress-of-packed-member' in Clang
4.0.0.