@@ -2755,6 +2755,9 @@ check_and_warn_address_of_packed_member (tree type, tree rhs)
while (TREE_CODE (rhs) == COMPOUND_EXPR)
rhs = TREE_OPERAND (rhs, 1);
+ if (TREE_CODE (rhs) == NOP_EXPR)
+ rhs = TREE_OPERAND (rhs, 0);
+
tree context = check_address_of_packed_member (type, rhs);
if (context)
{
@@ -2844,9 +2847,6 @@ warn_for_address_or_pointer_of_packed_member (bool convert_p, tree type,
/* Get the type of the pointer pointing to. */
type = TREE_TYPE (type);
- if (TREE_CODE (rhs) == NOP_EXPR)
- rhs = TREE_OPERAND (rhs, 0);
-
check_and_warn_address_of_packed_member (type, rhs);
}
}
new file mode 100644
@@ -0,0 +1,19 @@
+/* PR c/51628. */
+/* { dg-do compile } */
+/* { dg-options "-O" } */
+
+struct pair_t
+{
+ char x;
+ int i[4];
+} __attribute__ ((packed, aligned (4)));
+
+extern struct pair_t p;
+extern void bar (int *);
+
+void
+foo (struct pair_t *p)
+{
+ bar (p ? p->i : (int *) 0);
+/* { dg-warning "may result in an unaligned pointer value" "" { target *-*-* } .-1 } */
+}