On Thu, Jun 16, 2022 at 3:37 PM Vit Kabele <vit.kab...@sysgo.com> wrote: > > When the compiler warns about padding struct to alignment boundary, it > now also informs the user about the size of the alignment that needs to > be added to get rid of the warning.
Hi, thanks for taking the time to improve -Wpadded; I have been wishing that GCC's implementation of -Wpadded would print this information for a while now and thought there was a bug open for it, but can't seem to find it now... > > This removes the need of using pahole or similar tools, or manually > determining the padding size. > > Tested on x86_64-pc-linux-gnu. > > gcc/ChangeLog: > > * stor-layout.cc (finalize_record_size): Improve warning message > > Signed-off-by: Vit Kabele <vit.kab...@sysgo.com> > --- > gcc/stor-layout.cc | 9 ++++++++- > 1 file changed, 8 insertions(+), 1 deletion(-) > > diff --git a/gcc/stor-layout.cc b/gcc/stor-layout.cc > index 765f22f68b9..57ddb001780 100644 > --- a/gcc/stor-layout.cc > +++ b/gcc/stor-layout.cc > @@ -1781,7 +1781,14 @@ finalize_record_size (record_layout_info rli) > && 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 padding_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", > + padding_size); > + } Style nit: indentation seems off; check your tabs vs. spaces etc. > > if (warn_packed && TREE_CODE (rli->t) == RECORD_TYPE > && TYPE_PACKED (rli->t) && ! rli->packed_maybe_necessary > -- > 2.30.2