On Tue, Jan 22, 2019 at 02:10:38PM +0000, Bernd Edlinger wrote:
> --- gcc/c-family/c-warn.c (revision 268119)
> +++ gcc/c-family/c-warn.c (working copy)
> @@ -2796,6 +2796,10 @@ check_address_or_pointer_of_packed_membe
> if (context)
> break;
> }
> + if (TREE_CODE (TREE_TYPE (rhs)) == ARRAY_TYPE)
> + rvalue = false;
> + if (rvalue)
> + return NULL_TREE;
That looks like ARRAY_REF specific stuff, isn't it? We have various other
handled components, does e.g. REALPART_EXPR/IMAGPART_EXPR need that?
What about VIEW_CONVERT_EXPR? Or is that something you want to do for
all of them? In any case, there should be testcases with _Complex and
__real__/__imag__, address of that as well as value.
> @@ -52,4 +54,6 @@ void foo (void)
> i1 = t0.d; /* { dg-warning "may result in an unaligned
> pointer value" } */
> i1 = t1->d; /* { dg-warning "may result in an unaligned
> pointer value" } */
> i1 = t10[0].d; /* { dg-warning "may result in an unaligned
> pointer value" } */
> + i1 = (int*) &t10[0].e[0]; /* { dg-warning "may result in an unaligned
> pointer value" } */
> + i1 = (int*) t10[0].e; /* { dg-warning "may result in an unaligned
> pointer value" } */
Why not also i1 = &t10[0].e[0];
and i1 = t10[0].e; tests?
Unrelated to this patch, I'm worried e.g. about
if (INDIRECT_REF_P (rhs))
rhs = TREE_OPERAND (rhs, 0);
at the start of the check_address_or_pointer_of_packed_member
function, what if we have:
i1 = *&t0.c;
Do we want to warn when in the end we don't care if the address is unaligned
or not, this is folded eventually into t0.c.
Plus as I said earlier to H.J., I think
bool nop_p;
while (TREE_CODE (rhs) == COMPOUND_EXPR)
rhs = TREE_OPERAND (rhs, 1);
tree orig_rhs = rhs;
STRIP_NOPS (rhs);
nop_p = orig_rhs != rhs;
should be really:
bool nop_p;
tree orig_rhs = rhs;
STRIP_NOPS (rhs);
nop_p = orig_rhs != rhs;
while (TREE_CODE (rhs) == COMPOUND_EXPR)
rhs = TREE_OPERAND (rhs, 1);
orig_rhs = rhs;
STRIP_NOPS (rhs);
nop_p |= orig_rhs != rhs;
or similar, because if there are casts around COMPOUND_EXPR, it doesn't than
look through those COMPOUND_EXPRs, and if e.g. in the COMPOUND_EXPR rhs
there is then COND_EXPR or similar, it should handle that case.
Jakub