public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Qing Zhao <qing.zhao@oracle.com>,
	Richard Biener <rguenther@suse.de>,
	"gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>
Subject: [committed] ubsan: Add another testcase for [0] array in the middle of struct [PR108894]
Date: Wed, 1 Mar 2023 10:58:14 +0100	[thread overview]
Message-ID: <Y/8htiwLe6udGBN5@tucnak> (raw)
In-Reply-To: <Y/547iR6g2Lt8lY1@tucnak>

Hi!

On Tue, Feb 28, 2023 at 10:59:03PM +0100, Jakub Jelinek via Gcc-patches wrote:
> On Tue, Feb 28, 2023 at 07:19:40PM +0000, Qing Zhao wrote:
> > Understood.  
> > So, your patch fixed this bug, and then [0] arrays are instrumented by default with this patch.
> > 
> > > Well, it would complain about
> > > struct S { int a; int b[0]; int c; } s;
> > > ... &s.b[1] ...
> > > for C++, but not for C.
> > 
> > A little confused here: [0] arrays were instrumented by default for C++ if it’s not a trailing array, but not for C?
> 
> Given say
> 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];
> }

And, when I wrote such a testcase, I thought it would be worth it to have it
in the testsuite too.
Tested on x86_64-linux -m32/-m64, committed to trunk as obvious:

2023-03-01  Jakub Jelinek  <jakub@redhat.com>

	PR sanitizer/108894
	* c-c++-common/ubsan/bounds-16.c: New test.

--- gcc/testsuite/c-c++-common/ubsan/bounds-16.c.jj	2023-03-01 10:35:29.751959193 +0100
+++ gcc/testsuite/c-c++-common/ubsan/bounds-16.c	2023-03-01 10:38:09.087645556 +0100
@@ -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];
+}


	Jakub


  reply	other threads:[~2023-03-01  9:58 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-28  8:26 [PATCH] ubsan: Honor -fstrict-flex-arrays= in -fsanitize=bounds [PR108894] Jakub Jelinek
2023-02-28  9:02 ` Richard Biener
2023-02-28  9:11   ` Jakub Jelinek
2023-02-28 16:13 ` Qing Zhao
2023-02-28 17:49   ` Jakub Jelinek
2023-02-28 19:19     ` Qing Zhao
2023-02-28 21:59       ` Jakub Jelinek
2023-03-01  9:58         ` Jakub Jelinek [this message]
2023-03-01 16:30         ` Qing Zhao

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=Y/8htiwLe6udGBN5@tucnak \
    --to=jakub@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=qing.zhao@oracle.com \
    --cc=rguenther@suse.de \
    /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).