On Sat, Jan 20, 2018 at 9:50 AM, H.J. Lu wrote: > On Sat, Jan 20, 2018 at 8:31 AM, H.J. Lu wrote: >> On Fri, Jan 19, 2018 at 7:57 PM, Martin Sebor wrote: >>> On 01/19/2018 10:14 AM, Martin Sebor wrote: >>>> >> >>> After reading the Clang code review for the warning >>> (https://reviews.llvm.org/D20561) and experimenting with a few >>> more test cases I noticed some additional false negatives that >>> I think would be worthwhile diagnosing: >>> >>> struct A { >>> int i; >>> } __attribute__ ((packed)); >>> >>> int f (struct A *p) >>> { >>> return *&p->i; >>> } >> >> I now got >> >> [hjl@gnu-tools-1 pr51628]$ cat a1.i >> struct A { >> int i; >> } __attribute__ ((packed)); >> >> int f (struct A *p) >> { >> return *&p->i; >> } >> [hjl@gnu-tools-1 pr51628]$ make a1.s >> /export/build/gnu/gcc/build-x86_64-linux/gcc/xgcc >> -B/export/build/gnu/gcc/build-x86_64-linux/gcc/ -O2 -S a1.i >> a1.i: In function ‘f’: >> a1.i:7:10: warning: taking address of packed member of ‘struct A’ may >> result in an unaligned pointer value [-Waddress-of-packed-member] >> return *&p->i; >> ^~~~~~ >> [hjl@gnu-tools-1 pr51628]$ > > > It is wrong to warn "*&p->i;" since GCC always converts to "p->i;". Unless > we want to warn > > [hjl@gnu-tools-1 pr51628]$ cat g5.i > struct A { > int i; > } __attribute__ ((packed)); > > int f (struct A *p) > { > return p->i; > } > > we shouldn't warn: > > [hjl@gnu-tools-1 pr51628]$ cat a1.i > struct A { > int i; > } __attribute__ ((packed)); > > int f (struct A *p) > { > return *&p->i; > } > [hjl@gnu-tools-1 pr51628]$ > > There is no unaligned load here. I am testing a new patch. > Here is the updated patch. Tested on x86-64 and i686. -- H.J.