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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P1
                 CC|                            |hjl.tools at gmail dot com,
                   |                            |jakub at gcc dot gnu.org

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
I'd use just
struct S { short s; void *p; } __attribute__ ((__packed__));

int *
foo (struct S *x)
{
  return (int *) (x->p);
}
for both languages.

Despite quite many tests added in the -Waddress-of-packed-member commit, I
really don't see any testsuite coverage of the
              warning_at (location, OPT_Waddress_of_packed_member,
                          "converting a packed %qT pointer (alignment %d) "
                          "to %qT (alignment %d) may may result in an "
                          "unaligned pointer value",
                          rhstype, rhs_align, type, type_align);
warning (and note the "may may" bug in the wording there), is that covered by
anything?
As for the other path, it doesn't care whether address is taken or not:
  if (INDIRECT_REF_P (rhs))
    rhs = TREE_OPERAND (rhs, 0);

  if (TREE_CODE (rhs) == ADDR_EXPR)
    rhs = TREE_OPERAND (rhs, 0);
while it is significant.  We shouldn't warn if we are reading content from the
packed structure, but should warn if we are taking address (and for that needs
to take into account the array to pointer conversions, whether they happen
before or after this warning is reported).

Reply via email to