https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93910
Bug ID: 93910 Summary: -Waddress-of-packed-member triggered without actual access to a member or the address of a member Product: gcc Version: 9.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: stephane.goujet at wanadoo dot fr Target Milestone: --- Hello, This warning is triggered when I just cast the address of a packed structure to an int pointer. I am not trying to access (the address of) one of its members, which should be the sole purpose of this warning as I understand it. Here is the *.i from my test file, with a simplistic struct: ---------------------- # 1 "test2.c" # 1 "<built-in>" # 1 "<command-line>" # 31 "<command-line>" # 1 "/usr/include/stdc-predef.h" 1 3 4 # 32 "<command-line>" 2 # 1 "test2.c" struct __attribute__ ((__packed__)) S { int a; }; int main(void) { struct S s; char *pc = (char *) &s; int *pi = (int *) &s; return 0; } --------------------- and the compilation command and result: --------------------- ~/test/c/gcc9packed $LC_ALL=C gcc -Wextra test2.c -save-temps test2.c: In function 'main': test2.c:9:5: warning: converting a packed 'struct S' pointer (alignment 1) to a 'int' pointer (alignment 4) may result in an unaligned pointer value [-Waddress-of-packed-member] 9 | int *pi = (int *) &s; | ^~~ test2.c:2:37: note: defined here 2 | struct __attribute__ ((__packed__)) S { | --------------------- GCC version is 9.2.0: --------------------- ~/test/c/gcc9packed $LC_ALL=C gcc -v Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-pc-linux-gnu/9.2.0/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: ../gcc-9.2.0/configure --enable-gold=yes --enable-languages=d,fortran,objc : (reconfigured) ../gcc-9.2.0/configure --enable-gold=yes --enable-languages=d Thread model: posix gcc version 9.2.0 (GCC) --------------------- As a (not so important) side note, there are spelling mistakes in the French version of the warning message. One occurrence of 'pointer' is translated (to 'pointeur'), the other two remained in English: --------------------- test2.c: Dans la fonction « main »: test2.c:9:5: attention: convertir un pointer « struct S » compacté (alignement 1) vers un pointeur « int » (alignement 4) peut résulter en une valeur de pointer non alignée [-Waddress-of-packed-member] 9 | int *pi = (int *) &s; | ^~~ test2.c:2:37: note: défini ici 2 | struct __attribute__ ((__packed__)) S { | ----------------------