public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r13-6389] ubsan: Add another testcase for [0] array in the middle of struct [PR108894]
Date: Wed,  1 Mar 2023 09:51:16 +0000 (GMT)	[thread overview]
Message-ID: <20230301095116.7B6DD3858D3C@sourceware.org> (raw)

https://gcc.gnu.org/g:f72c8918416f67aad907752f1892c19eda12eecb

commit r13-6389-gf72c8918416f67aad907752f1892c19eda12eecb
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Wed Mar 1 10:49:38 2023 +0100

    ubsan: Add another testcase for [0] array in the middle of struct [PR108894]
    
    I think it is useful to cover also this, rather than just arrays at the
    flexible array member positions.
    
    2023-03-01  Jakub Jelinek  <jakub@redhat.com>
    
            PR sanitizer/108894
            * c-c++-common/ubsan/bounds-16.c: New test.

Diff:
---
 gcc/testsuite/c-c++-common/ubsan/bounds-16.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/gcc/testsuite/c-c++-common/ubsan/bounds-16.c b/gcc/testsuite/c-c++-common/ubsan/bounds-16.c
new file mode 100644
index 00000000000..0c27ff9cce4
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/ubsan/bounds-16.c
@@ -0,0 +1,15 @@
+/* PR sanitizer/108894 */
+/* { dg-do run } */
+/* { dg-options "-fsanitize=bounds -fsanitize-recover=bounds" } */
+/* { dg-output "index 1 out of bounds for type 'int \\\[\[*0-9x]*\\\]'\[^\n\r]*(\n|\r\n|\r)" } */
+/* { dg-output "\[^\n\r]*index 0 out of bounds for type 'int \\\[\[*0-9x]*\\\]'" } */
+
+struct S { int a; int b[0]; int c; } s;
+
+int
+main ()
+{
+  int *volatile p = &s.b[0];
+  p = &s.b[1];
+  int volatile q = s.b[0];
+}

                 reply	other threads:[~2023-03-01  9:51 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=20230301095116.7B6DD3858D3C@sourceware.org \
    --to=jakub@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).