* [PATCH] Print padding size when aligning struct member
@ 2023-02-07 12:41 Vít Kabele
2023-02-07 13:08 ` Andreas Schwab
0 siblings, 1 reply; 6+ messages in thread
From: Vít Kabele @ 2023-02-07 12:41 UTC (permalink / raw)
To: gcc-patches; +Cc: vit, Vít Kabele
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..fb1948b94af 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..35ff013026f 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 3 bytes to align 'i'" } */
diff --git a/gcc/testsuite/gcc.dg/Wpadded.c b/gcc/testsuite/gcc.dg/Wpadded.c
index 70fcd79a6d4..357e7f61e4a 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 7 bytes to align" "" { target { ! default_packed } } } */
} futz;
--
2.30.2
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Print padding size when aligning struct member
2023-02-07 12:41 [PATCH] Print padding size when aligning struct member Vít Kabele
@ 2023-02-07 13:08 ` Andreas Schwab
2023-02-07 14:09 ` Vit Kabele
2023-02-24 7:28 ` [PATCH v2] " Vít Kabele
0 siblings, 2 replies; 6+ messages in thread
From: Andreas Schwab @ 2023-02-07 13:08 UTC (permalink / raw)
To: Vít Kabele; +Cc: gcc-patches, vit
On Feb 07 2023, Vít Kabele wrote:
> diff --git a/gcc/testsuite/gcc.dg/Wpadded.c b/gcc/testsuite/gcc.dg/Wpadded.c
> index 70fcd79a6d4..357e7f61e4a 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 7 bytes to align" "" { target { ! default_packed } } } */
The actual amount of padding is target dependent.
--
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE 1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Print padding size when aligning struct member
2023-02-07 13:08 ` Andreas Schwab
@ 2023-02-07 14:09 ` Vit Kabele
2023-02-24 7:28 ` [PATCH v2] " Vít Kabele
1 sibling, 0 replies; 6+ messages in thread
From: Vit Kabele @ 2023-02-07 14:09 UTC (permalink / raw)
To: Andreas Schwab; +Cc: gcc-patches, vit
On Tue, Feb 07, 2023 at 02:08:35PM +0100, Andreas Schwab wrote:
> On Feb 07 2023, Vít Kabele wrote:
>
> > diff --git a/gcc/testsuite/gcc.dg/Wpadded.c b/gcc/testsuite/gcc.dg/Wpadded.c
> > index 70fcd79a6d4..357e7f61e4a 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 7 bytes to align" "" { target { ! default_packed } } } */
>
> The actual amount of padding is target dependent.
Ah sorry, would removing everything after `with...` be ok?
Like this:
> + long baz; /* { dg-warning "padding struct with" "" { target { ! default_packed } } } */
--
Best regards,
Vit Kabele
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2] Print padding size when aligning struct member
2023-02-07 13:08 ` Andreas Schwab
2023-02-07 14:09 ` Vit Kabele
@ 2023-02-24 7:28 ` Vít Kabele
2023-03-11 15:35 ` Jeff Law
1 sibling, 1 reply; 6+ messages in thread
From: Vít Kabele @ 2023-02-24 7:28 UTC (permalink / raw)
To: gcc-patches; +Cc: vit, Vít Kabele
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] Print padding size when aligning struct member
2023-02-24 7:28 ` [PATCH v2] " Vít Kabele
@ 2023-03-11 15:35 ` Jeff Law
2023-03-28 14:24 ` Vit Kabele
0 siblings, 1 reply; 6+ messages in thread
From: Jeff Law @ 2023-03-11 15:35 UTC (permalink / raw)
To: Vít Kabele, gcc-patches; +Cc: vit
On 2/24/23 00:28, Vít Kabele wrote:
> Hello,
>
> I changed the tested pattern to match even on targets with different
> alignment.
So this needs to wait for stage1 development to open -- we're in
regression bugfixing phase only right now. I would expect that to
happen in April/May.
You might consider changing the other similar message you added last
year to finalize_record_size to use the same format as this message for
the sake of consistency.
Jeff
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] Print padding size when aligning struct member
2023-03-11 15:35 ` Jeff Law
@ 2023-03-28 14:24 ` Vit Kabele
0 siblings, 0 replies; 6+ messages in thread
From: Vit Kabele @ 2023-03-28 14:24 UTC (permalink / raw)
To: Jeff Law, gcc-patches; +Cc: vit
Hello,
On Sat, Mar 11, 2023 at 08:35:53AM -0700, Jeff Law wrote:
> On 2/24/23 00:28, Vít Kabele wrote:
> You might consider changing the other similar message you added last year to
> finalize_record_size to use the same format as this message for the sake of
> consistency.
For example like this?
- padding struct with %d bytes to align %q+D
+ padding struct to align %q+D with %d bytes
to be consistent with:
padding struct size to alignment boundary with %E bytes
--
Best regards,
Vit Kabele
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2023-03-28 14:24 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-07 12:41 [PATCH] Print padding size when aligning struct member Vít Kabele
2023-02-07 13:08 ` Andreas Schwab
2023-02-07 14:09 ` Vit Kabele
2023-02-24 7:28 ` [PATCH v2] " Vít Kabele
2023-03-11 15:35 ` Jeff Law
2023-03-28 14:24 ` Vit Kabele
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).