On Mon, May 14, 2018 at 10:40 AM, H.J. Lu <hjl.to...@gmail.com> wrote:
>>>> $ cat c.i >>>> struct B { int i; }; >>>> struct C { struct B b; } __attribute__ ((packed)); >>>> >>>> long* g8 (struct C *p) { return p; } >>>> $ gcc -O2 -S c.i -Wno-incompatible-pointer-types >>>> c.i: In function ‘g8’: >>>> c.i:4:33: warning: taking value of packed 'struct C *' may result in an >>>> unaligned pointer value [-Waddress-of-packed-member] >> >> ^^^^^ >> That should read "taking address" (not value) but... > > The value of 'struct C *' is an address. There is no address taken here. > >> ...to help explain the problem I would suggest to mention the expected >> and actual alignment in the warning message. E.g., >> >> storing the address of a packed 'struct C' in 'struct C *' increases the >> alignment of the pointer from 1 to 4. > > I will take a look. > >> (IIUC, the source type and destination type need not be the same so >> including both should be helpful in those cases.) >> >> Adding a note pointing to the declaration of either the struct or >> the member would help users find it if it's a header far removed >> from the point of use. > > I will see what I can do. How about this [hjl@gnu-skx-1 pr51628]$ cat n9.i struct B { int i; }; struct C { struct B b; } __attribute__ ((packed)); long* g8 (struct C *p) { return p; } [hjl@gnu-skx-1 pr51628]$ /export/build/gnu/gcc-test/build-x86_64-linux/gcc/xgcc -B/export/build/gnu/gcc-test/build-x86_64-linux/gcc/ -O2 -S n9.i n9.i: In function ‘g8’: n9.i:4:33: warning: returning ‘struct C *’ from a function with incompatible return type ‘long int *’ [-Wincompatible-pointer-types] long* g8 (struct C *p) { return p; } ^ n9.i:4:33: warning: taking value of packed ‘struct C *’ increases the alignment of the pointer from 1 to 8 [-Waddress-of-packed-member] n9.i:2:8: note: defined here struct C { struct B b; } __attribute__ ((packed)); ^ [hjl@gnu-skx-1 pr51628]$ -- H.J.