Given the following source: typedef unsigned char uint8_t; typedef unsigned short int uint16_t; typedef unsigned int uint32_t; struct a { uint8_t f0; uint8_t f1; uint16_t f2; } __attribute__((packed)); struct b { uint16_t f0; }; void test (struct a *p) { struct b *q= (struct b *)p; } when compiled with -w, gcc 9 emits just these stray notes: rhbz1696441.c: In function ‘test’: ../../src/rhbz1696441.c:5:8: note: defined here 5 | struct a { | ^ rhbz1696441.c:11:8: note: defined here 11 | struct b { | ^ (from downstream report https://bugzilla.redhat.com/show_bug.cgi?id=1696441 ) The notes are followups to -Waddress-of-packed-member warnings, which aren't being properly guarded by emission of that warning in c-family/c-warn.c: 2776 warning_at (location, OPT_Waddress_of_packed_member, 2777 "converting a packed %qT pointer (alignment %d) " 2778 "to a %qT pointer (alignment %d) may result in an " 2779 "unaligned pointer value", 2780 rhstype, rhs_align, type, type_align); 2781 tree decl = TYPE_STUB_DECL (rhstype); 2782 if (decl) 2783 inform (DECL_SOURCE_LOCATION (decl), "defined here"); 2784 decl = TYPE_STUB_DECL (type); 2785 if (decl) 2786 inform (DECL_SOURCE_LOCATION (decl), "defined here"); which is normally guarded by: 2886 warn_for_address_or_pointer_of_packed_member (tree type, tree rhs) 2887 { 2888 if (!warn_address_of_packed_member) 2889 return; but the "-w" sidesteps this (via diagnostic_report_warnings_p). Appears to be new with gcc 9. I'm working on a fix.
Author: dmalcolm Date: Fri Apr 5 15:15:37 2019 New Revision: 270169 URL: https://gcc.gnu.org/viewcvs?rev=270169&root=gcc&view=rev Log: Guard notes for -Waddress-of-packed-member on warning emission (PR c/89985) gcc/c-family/ChangeLog: PR c/89985 * c-warn.c (check_address_or_pointer_of_packed_member): Add auto_diagnostic_group. Guard inform calls by result of warning_at call. gcc/testsuite/ChangeLog: PR c/89985 * c-c++-common/pr89985.c: New test. Added: trunk/gcc/testsuite/c-c++-common/pr89985.c Modified: trunk/gcc/c-family/ChangeLog trunk/gcc/c-family/c-warn.c trunk/gcc/testsuite/ChangeLog
Should be fixed by r270169.
since the issue of calls to inform being done without checking the return value of warning[_at] first seems to keep coming up, I almost wonder if it's worth adding __attribute__((unused_result)) to warning[_at]...
(In reply to Eric Gallager from comment #3) > since the issue of calls to inform being done without checking the return > value of warning[_at] first seems to keep coming up, I almost wonder if it's > worth adding __attribute__((unused_result)) to warning[_at]... er __attribute__((warn_unused_result)) I mean