public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-1588] [PATCH v3] c: Extend the -Wpadded message with actual padding size
@ 2022-07-09 17:07 Jeff Law
  0 siblings, 0 replies; only message in thread
From: Jeff Law @ 2022-07-09 17:07 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:7a16d39903ed1bf159f7933a19ccae62155b371b

commit r13-1588-g7a16d39903ed1bf159f7933a19ccae62155b371b
Author: Vit Kabele <vit.kabele@sysgo.com>
Date:   Sat Jul 9 13:06:43 2022 -0400

    [PATCH v3] c: Extend the -Wpadded message with actual padding size
    
    gcc/ChangeLog:
    
            * stor-layout.cc (finalize_record_size): Extend warning message.
    
    gcc/testsuite/ChangeLog:
    
            * c-c++-common/Wpadded.c: New test.

Diff:
---
 gcc/stor-layout.cc                   |  7 ++++++-
 gcc/testsuite/c-c++-common/Wpadded.c | 14 ++++++++++++++
 2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/gcc/stor-layout.cc b/gcc/stor-layout.cc
index 765f22f68b9..88923c4136b 100644
--- a/gcc/stor-layout.cc
+++ b/gcc/stor-layout.cc
@@ -1781,7 +1781,12 @@ 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 pad_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", pad_size);
+  }
 
   if (warn_packed && TREE_CODE (rli->t) == RECORD_TYPE
       && TYPE_PACKED (rli->t) && ! rli->packed_maybe_necessary
diff --git a/gcc/testsuite/c-c++-common/Wpadded.c b/gcc/testsuite/c-c++-common/Wpadded.c
new file mode 100644
index 00000000000..c5be4686822
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/Wpadded.c
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-options "-Wpadded" } */
+
+/*
+ * The struct is on single line, because C++ compiler emits the -Wpadded
+ * warning at the first line of the struct definition, while the C compiler at
+ * the last line. This way the test passes on both.
+ *
+ * Attribute aligned is needed for the test to pass on targets where
+ * the default behaviour is to pack the struct and also on targets that align
+ * 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" } */
+


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-07-09 17:07 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-09 17:07 [gcc r13-1588] [PATCH v3] c: Extend the -Wpadded message with actual padding size Jeff Law

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).