From: Marek Polacek <polacek@redhat.com>
To: Vit Kabele <vit.kabele@sysgo.com>
Cc: gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] c: Extend the -Wpadded message with actual padding size
Date: Fri, 17 Jun 2022 10:06:26 -0400 [thread overview]
Message-ID: <YqyKYu76ofyqZk7h@redhat.com> (raw)
In-Reply-To: <YquGfJwdWbZMuaQK@czspare1-lap.sysgo.cz>
On Thu, Jun 16, 2022 at 09:37:32PM +0200, Vit Kabele 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.
>
> This removes the need of using pahole or similar tools, or manually
> determining the padding size.
Thanks for the patch, it looks reasonable, with the formatting fixed.
It would be nice to have a testcase, at least something like
struct S {
__UINT64_TYPE__ i;
char c;
};
The problem is what value to check for, on 32-bit arches the padding is
probably 3 bytes large and on 64-bit arches probably 7 bytes. So I think
you could use __attribute__((aligned (8))) and then it's always 7.
> Tested on x86_64-pc-linux-gnu.
>
> gcc/ChangeLog:
>
> * stor-layout.cc (finalize_record_size): Improve warning message
Missing '.' at the end.
>
> Signed-off-by: Vit Kabele <vit.kabele@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);
> + }
>
> if (warn_packed && TREE_CODE (rli->t) == RECORD_TYPE
> && TYPE_PACKED (rli->t) && ! rli->packed_maybe_necessary
> --
> 2.30.2
>
Marek
next prev parent reply other threads:[~2022-06-17 14:06 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-16 19:37 Vit Kabele
2022-06-17 12:56 ` Eric Gallager
2022-06-17 14:06 ` Marek Polacek [this message]
2022-06-20 13:50 ` Vit Kabele
2022-06-20 23:05 ` Andrew Pinski
2022-06-22 8:34 ` Vit Kabele
2022-06-22 8:47 ` Andrew Pinski
2022-06-22 11:50 ` [PATCH v2] " Vit Kabele
2022-06-27 8:04 ` [PATCH v3] " Vit Kabele
2022-07-09 17:07 ` Jeff Law
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YqyKYu76ofyqZk7h@redhat.com \
--to=polacek@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=vit.kabele@sysgo.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).