gcc/ChangeLog:
* stor-layout.cc (finalize_record_size): Extend warning message.
gcc/testsuite/ChangeLog:
* c-c++-common/Wpadded.c: New test.
&& simple_cst_equal (unpadded_size, TYPE_SIZE (rli->t)) == 0
&& input_location != BUILTINS_LOCATION
&& !TYPE_ARTIFICIAL (rli->t))
- warning (OPT_Wpadded, "padding struct size to alignment boundary");
+ {
+ tree pad_size
+ = size_binop (MINUS_EXPR, TYPE_SIZE_UNIT (rli->t), unpadded_size_unit);
+ warning (OPT_Wpadded,
+ "padding struct size to alignment boundary with %E bytes", pad_size);
+ }
if (warn_packed && TREE_CODE (rli->t) == RECORD_TYPE
&& TYPE_PACKED (rli->t) && ! rli->packed_maybe_necessary
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-Wpadded" } */
+
+/*
+ * The struct is on single line, because C++ compiler emits the -Wpadded
+ * warning at the first line of the struct definition, while the C compiler at
+ * the last line. This way the test passes on both.
+ *
+ * Attribute aligned is needed for the test to pass on targets where
+ * the default behaviour is to pack the struct and also on targets that align
+ * 4 byte fields to 2 byte boundary.
+ */
+struct S { __UINT32_TYPE__ i; char c; } __attribute__((aligned(4))); /* { dg-warning "padding struct size to alignment boundary with 3 bytes" } */
+