[v2] Print padding size when aligning struct member
Checks
Commit Message
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(-)
Comments
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
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
@@ -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. */
@@ -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" } */
@@ -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;