public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Dimitar Dimitrov <dimitar@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r13-1259] testsuite: Handle default_packed for gcc.dg/builtin-object-size-20.c
Date: Fri, 24 Jun 2022 20:26:05 +0000 (GMT)	[thread overview]
Message-ID: <20220624202605.DC19F383DB91@sourceware.org> (raw)

https://gcc.gnu.org/g:5cd0e800195ce0f5cb88cde3f2e98b102174847a

commit r13-1259-g5cd0e800195ce0f5cb88cde3f2e98b102174847a
Author: Dimitar Dimitrov <dimitar@dinux.eu>
Date:   Fri May 13 22:46:59 2022 +0300

    testsuite: Handle default_packed for gcc.dg/builtin-object-size-20.c
    
    The gcc.dg/builtin-object-size-20.c test case assumes that the target
    inserts padding between structure members.  Obviously it fails for
    targets which pack structures by default.
    
    Split the cases into two tests, so that the ones requiring structure
    padding can be skipped for default_packed targets.
    
    gcc/testsuite/ChangeLog:
    
            * gcc.dg/builtin-object-size-20.c: Remove cases which
            work on default_packed targets.
            * gcc.dg/builtin-object-size-22.c: New test with the cases
            removed above.
    
    Signed-off-by: Dimitar Dimitrov <dimitar@dinux.eu>

Diff:
---
 gcc/testsuite/gcc.dg/builtin-object-size-20.c | 64 +---------------------
 gcc/testsuite/gcc.dg/builtin-object-size-22.c | 79 +++++++++++++++++++++++++++
 2 files changed, 81 insertions(+), 62 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/builtin-object-size-20.c b/gcc/testsuite/gcc.dg/builtin-object-size-20.c
index bed973c2c77..f40e3dcc1a9 100644
--- a/gcc/testsuite/gcc.dg/builtin-object-size-20.c
+++ b/gcc/testsuite/gcc.dg/builtin-object-size-20.c
@@ -1,7 +1,8 @@
 /* PR middle-end/92815 - spurious -Wstringop-overflow writing into
    a flexible array of an extern struct
    { dg-do compile }
-   { dg-options "-O -Wall -fdump-tree-optimized" } */
+   { dg-options "-O -Wall -fdump-tree-optimized" }
+   { dg-skip-if "test assumes that structs have padding" { default_packed } } */
 
 #define ASSERT(expr) ((expr) ? (void)0 : fail (__LINE__))
 #define bos0(expr) __builtin_object_size (expr, 1)
@@ -18,44 +19,6 @@ typedef __SIZE_TYPE__  size_t;
 extern void fail (int);
 
 
-/* Verify sizes of a struct with a flexible array member and no padding.  */
-
-struct ACX { char n, a[]; };
-
-struct ACX ac0 = { };
-struct ACX ac1 = { 1, { 1 } };
-struct ACX ac2 = { 2, { 1, 2 } };
-struct ACX ac3 = { 3, { 1, 2, 3 } };
-
-extern struct ACX eacx;
-
-void facx (void)
-{
-  ASSERT (bos0 (&ac0) == sizeof ac0);
-  ASSERT (bos0 (&ac1) == 2);
-  ASSERT (bos0 (&ac2) == 3);
-  ASSERT (bos0 (&ac3) == 4);
-  ASSERT (bos0 (&eacx) == (size_t)-1);
-
-  ASSERT (bos1 (&ac0) == sizeof ac0);
-  ASSERT (bos1 (&ac1) == 2);
-  ASSERT (bos1 (&ac2) == 3);
-  ASSERT (bos1 (&ac3) == 4);
-  ASSERT (bos1 (&eacx) == (size_t)-1);
-
-  ASSERT (bos2 (&ac0) == sizeof ac0);
-  ASSERT (bos2 (&ac1) == 2);
-  ASSERT (bos2 (&ac2) == 3);
-  ASSERT (bos2 (&ac3) == 4);
-  ASSERT (bos2 (&eacx) == sizeof eacx);
-
-  ASSERT (bos3 (&ac0) == sizeof ac0);
-  ASSERT (bos3 (&ac1) == 2);
-  ASSERT (bos3 (&ac2) == 3);
-  ASSERT (bos3 (&ac3) == 4);
-  ASSERT (bos3 (&eacx) == sizeof eacx);
-}
-
 
 
 /* Verify sizes of a struct with a flexible array member and 1 byte
@@ -289,27 +252,4 @@ void fai64cx (void)
   ASSERT (bos3 (&eai64cx) == sizeof eai64cx);
 }
 
-
-/* Also verify sizes of a struct with a zero length array member.  */
-
-struct A0C0 { char n, a[0]; };
-
-struct A0C0 a0c0 = { };
-extern struct A0C0 ea0c0;
-
-void fa0c0 (void)
-{
-  ASSERT (bos0 (&a0c0) == sizeof a0c0);
-  ASSERT (bos0 (&ea0c0) == sizeof ea0c0);
-
-  ASSERT (bos1 (&a0c0) == sizeof a0c0);
-  ASSERT (bos1 (&a0c0) == sizeof ea0c0);
-
-  ASSERT (bos2 (&a0c0) == sizeof a0c0);
-  ASSERT (bos2 (&a0c0) == sizeof ea0c0);
-
-  ASSERT (bos3 (&a0c0) == sizeof a0c0);
-  ASSERT (bos3 (&a0c0) == sizeof ea0c0);
-}
-
 /* { dg-final { scan-tree-dump-not "fail" "optimized" } } */
diff --git a/gcc/testsuite/gcc.dg/builtin-object-size-22.c b/gcc/testsuite/gcc.dg/builtin-object-size-22.c
new file mode 100644
index 00000000000..1e55229c949
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/builtin-object-size-22.c
@@ -0,0 +1,79 @@
+/* PR middle-end/92815 - a variant of gcc.dg/builtin-object-size-20.c
+   prepared for all targets, irregardless if they pack or not
+   the structs by default.
+   { dg-do compile }
+   { dg-options "-O -Wall -fdump-tree-optimized" } */
+
+#define ASSERT(expr) ((expr) ? (void)0 : fail (__LINE__))
+#define bos0(expr) __builtin_object_size (expr, 1)
+#define bos1(expr) __builtin_object_size (expr, 1)
+#define bos2(expr) __builtin_object_size (expr, 2)
+#define bos3(expr) __builtin_object_size (expr, 3)
+
+typedef __SIZE_TYPE__  size_t;
+
+
+extern void fail (int);
+
+
+/* Verify sizes of a struct with a flexible array member and no padding.  */
+
+struct ACX { char n, a[]; };
+
+struct ACX ac0 = { };
+struct ACX ac1 = { 1, { 1 } };
+struct ACX ac2 = { 2, { 1, 2 } };
+struct ACX ac3 = { 3, { 1, 2, 3 } };
+
+extern struct ACX eacx;
+
+void facx (void)
+{
+  ASSERT (bos0 (&ac0) == sizeof ac0);
+  ASSERT (bos0 (&ac1) == 2);
+  ASSERT (bos0 (&ac2) == 3);
+  ASSERT (bos0 (&ac3) == 4);
+  ASSERT (bos0 (&eacx) == (size_t)-1);
+
+  ASSERT (bos1 (&ac0) == sizeof ac0);
+  ASSERT (bos1 (&ac1) == 2);
+  ASSERT (bos1 (&ac2) == 3);
+  ASSERT (bos1 (&ac3) == 4);
+  ASSERT (bos1 (&eacx) == (size_t)-1);
+
+  ASSERT (bos2 (&ac0) == sizeof ac0);
+  ASSERT (bos2 (&ac1) == 2);
+  ASSERT (bos2 (&ac2) == 3);
+  ASSERT (bos2 (&ac3) == 4);
+  ASSERT (bos2 (&eacx) == sizeof eacx);
+
+  ASSERT (bos3 (&ac0) == sizeof ac0);
+  ASSERT (bos3 (&ac1) == 2);
+  ASSERT (bos3 (&ac2) == 3);
+  ASSERT (bos3 (&ac3) == 4);
+  ASSERT (bos3 (&eacx) == sizeof eacx);
+}
+
+/* Also verify sizes of a struct with a zero length array member.  */
+
+struct A0C0 { char n, a[0]; };
+
+struct A0C0 a0c0 = { };
+extern struct A0C0 ea0c0;
+
+void fa0c0 (void)
+{
+  ASSERT (bos0 (&a0c0) == sizeof a0c0);
+  ASSERT (bos0 (&ea0c0) == sizeof ea0c0);
+
+  ASSERT (bos1 (&a0c0) == sizeof a0c0);
+  ASSERT (bos1 (&a0c0) == sizeof ea0c0);
+
+  ASSERT (bos2 (&a0c0) == sizeof a0c0);
+  ASSERT (bos2 (&a0c0) == sizeof ea0c0);
+
+  ASSERT (bos3 (&a0c0) == sizeof a0c0);
+  ASSERT (bos3 (&a0c0) == sizeof ea0c0);
+}
+
+/* { dg-final { scan-tree-dump-not "fail" "optimized" } } */


                 reply	other threads:[~2022-06-24 20:26 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20220624202605.DC19F383DB91@sourceware.org \
    --to=dimitar@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /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).