+2019-04-05 David Malcolm <dmalcolm@redhat.com>
+
+ 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.
+
2019-04-05 Marek Polacek <polacek@redhat.com>
PR c++/89973 - -Waddress-of-packed-member ICE with invalid conversion.
unsigned int rhs_align = min_align_of_type (rhstype);
if (rhs_align < type_align)
{
+ auto_diagnostic_group d;
location_t location = EXPR_LOC_OR_LOC (rhs, input_location);
- warning_at (location, OPT_Waddress_of_packed_member,
- "converting a packed %qT pointer (alignment %d) "
- "to a %qT pointer (alignment %d) may result in an "
- "unaligned pointer value",
- rhstype, rhs_align, type, type_align);
- tree decl = TYPE_STUB_DECL (rhstype);
- if (decl)
- inform (DECL_SOURCE_LOCATION (decl), "defined here");
- decl = TYPE_STUB_DECL (type);
- if (decl)
- inform (DECL_SOURCE_LOCATION (decl), "defined here");
+ if (warning_at (location, OPT_Waddress_of_packed_member,
+ "converting a packed %qT pointer (alignment %d) "
+ "to a %qT pointer (alignment %d) may result in "
+ "an unaligned pointer value",
+ rhstype, rhs_align, type, type_align))
+ {
+ tree decl = TYPE_STUB_DECL (rhstype);
+ if (decl)
+ inform (DECL_SOURCE_LOCATION (decl), "defined here");
+ decl = TYPE_STUB_DECL (type);
+ if (decl)
+ inform (DECL_SOURCE_LOCATION (decl), "defined here");
+ }
}
}
return NULL_TREE;
--- /dev/null
+/* Ensure that -Waddress-of-packed-member doesn't emit notes when
+ suppressed via -w, rather than -Wno-address-of-packed-member. */
+
+/* { dg-do compile } */
+/* { dg-options "-w" } */
+
+struct a { /* { dg-bogus "defined here" } */
+ void *ptr;
+} __attribute__((packed));
+
+struct b { /* { dg-bogus "defined here" } */
+ void *ptr;
+};
+
+void
+test (struct a *p)
+{
+ struct b *q = (struct b *)p;
+}