From: "Vít Kabele" <vit.kabele@sysgo.com>
To: gcc-patches@gcc.gnu.org
Cc: vit@kabele.me, "Vít Kabele" <vit.kabele@sysgo.com>
Subject: [PATCH v2] Print padding size when aligning struct member
Date: Fri, 24 Feb 2023 08:28:36 +0100 [thread overview]
Message-ID: <20230224072835.12177-1-vit.kabele@sysgo.com> (raw)
In-Reply-To: <mvmedr1wrl8.fsf@suse.de>
Hello,
I changed the tested pattern to match even on targets with different
alignment.
BR,
VK
-- >8 --
Announce the size of introduced padding when compiling
with -Wpadded.
gcc/ChangeLog:
* stor-layout.cc (place_field): Change warning message format
gcc/testsuite/ChangeLog:
* c-c++-common/Wpadded.c: Add new testcase
* gcc.dg/Wpadded.c: Update the expected warning message
Signed-off-by: Vít Kabele <vit.kabele@sysgo.com>
---
gcc/stor-layout.cc | 2 +-
gcc/testsuite/c-c++-common/Wpadded.c | 1 +
gcc/testsuite/gcc.dg/Wpadded.c | 2 +-
3 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/gcc/stor-layout.cc b/gcc/stor-layout.cc
index 45bf2d18639..1d2bd61eeae 100644
--- a/gcc/stor-layout.cc
+++ b/gcc/stor-layout.cc
@@ -1346,7 +1346,7 @@ place_field (record_layout_info rli, tree field)
if (!targetm.ms_bitfield_layout_p (rli->t)
&& DECL_SOURCE_LOCATION (field) != BUILTINS_LOCATION
&& !TYPE_ARTIFICIAL (rli->t))
- warning (OPT_Wpadded, "padding struct to align %q+D", field);
+ warning (OPT_Wpadded, "padding struct with %d bytes to align %q+D", (desired_align - known_align)/8, field);
/* If the alignment is still within offset_align, just align
the bit position. */
diff --git a/gcc/testsuite/c-c++-common/Wpadded.c b/gcc/testsuite/c-c++-common/Wpadded.c
index c5be4686822..0818ea03690 100644
--- a/gcc/testsuite/c-c++-common/Wpadded.c
+++ b/gcc/testsuite/c-c++-common/Wpadded.c
@@ -11,4 +11,5 @@
* 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" } */
+struct R { char c; __UINT32_TYPE__ i; } __attribute__((aligned(4))); /* { dg-warning "padding struct with" } */
diff --git a/gcc/testsuite/gcc.dg/Wpadded.c b/gcc/testsuite/gcc.dg/Wpadded.c
index 70fcd79a6d4..218b37d1abc 100644
--- a/gcc/testsuite/gcc.dg/Wpadded.c
+++ b/gcc/testsuite/gcc.dg/Wpadded.c
@@ -10,5 +10,5 @@
struct foo {
char bar;
- long baz; /* { dg-warning "padding struct to align" "" { target { ! default_packed } } } */
+ long baz; /* { dg-warning "padding struct with" "" { target { ! default_packed } } } */
} futz;
--
2.30.2
next prev parent reply other threads:[~2023-02-24 7:30 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-07 12:41 [PATCH] " Vít Kabele
2023-02-07 13:08 ` Andreas Schwab
2023-02-07 14:09 ` Vit Kabele
2023-02-24 7:28 ` Vít Kabele [this message]
2023-03-11 15:35 ` [PATCH v2] " Jeff Law
2023-03-28 14:24 ` Vit Kabele
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=20230224072835.12177-1-vit.kabele@sysgo.com \
--to=vit.kabele@sysgo.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=vit@kabele.me \
/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).