https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90452

            Bug ID: 90452
           Summary: no warning for misaligned pointer to #pragma-pack'ed
                    fields
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: amonakov at gcc dot gnu.org
  Target Milestone: ---

GCC 9 introduced a new warning (-Waddress-of-packed-member) for situations
where the code tries to assign address of an under-aligned struct field to a
normal pointer (which should point to a properly aligned object).

However, the new warning doesn't trigger if unaligned fields appear under
#pragma pack (although funny that it works fine when -fpack-struct is given on
the command line):

#pragma pack(push,1)
struct
//__attribute__((packed))
s {
    char c;
    long l;
} *s;
#pragma pack(pop)

long *f()
{
    return &s->l;
}

Reply via email to