From: Qing Zhao <qing.zhao@oracle.com>
To: Jakub Jelinek <jakub@redhat.com>
Cc: "gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] ubsan: Honor -fstrict-flex-arrays= in -fsanitize=bounds [PR108894]
Date: Wed, 1 Mar 2023 16:30:13 +0000 [thread overview]
Message-ID: <FF997653-5B2D-40E1-8694-6AF4A94F7E29@oracle.com> (raw)
In-Reply-To: <Y/547iR6g2Lt8lY1@tucnak>
> On Feb 28, 2023, at 4:59 PM, Jakub Jelinek <jakub@redhat.com> 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];
> }
> both -fsanitize=bounds and -fsanitize=bounds-strict behaved the same way,
> in C nothing was reported, in C++ the p = &s.b[1]; statement.
> The reasons for s.b[0] not being reported in C++ was that for
> !ignore_off_by_one, bounds was ~(size_t)0, and so index > ~(size_t)0
> is always false. While with the committed patch it is
> index >= (~(size_t)0)+1 and so always true. And in C additionally, we
> punted early because TYPE_MAX_VALUE (domain) was NULL.
Thanks for the explanation.
With your patch, both C and C++ will report for the middle [0] arrays. That’s nice.
Qing
>
> Jakub
>
prev parent reply other threads:[~2023-03-01 16:30 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-28 8:26 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 ` [committed] ubsan: Add another testcase for [0] array in the middle of struct [PR108894] Jakub Jelinek
2023-03-01 16:30 ` Qing Zhao [this message]
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=FF997653-5B2D-40E1-8694-6AF4A94F7E29@oracle.com \
--to=qing.zhao@oracle.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jakub@redhat.com \
/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).