From: Marek Polacek <polacek@redhat.com>
To: Jakub Jelinek <jakub@redhat.com>
Cc: Richard Biener <rguenther@suse.de>,
GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH v2] ubsan: missed -fsanitize=bounds for compound ops [PR108060]
Date: Fri, 10 Mar 2023 13:09:54 -0500 [thread overview]
Message-ID: <ZAtycrmn2QE+zmG/@redhat.com> (raw)
In-Reply-To: <ZAtx6Eu/AuGGEWJZ@tucnak>
On Fri, Mar 10, 2023 at 07:07:36PM +0100, Jakub Jelinek wrote:
> On Thu, Mar 09, 2023 at 07:44:53PM -0500, Marek Polacek wrote:
> > On Thu, Mar 09, 2023 at 09:44:49AM +0100, Jakub Jelinek wrote:
> > > On Thu, Mar 09, 2023 at 08:12:47AM +0000, Richard Biener wrote:
> > > > I think this is a reasonable way to address the regression, so OK.
> > >
> > > It is true that both C and C++ (including c++14_down and c++17 and later
> > > where the latter have different ordering rules) evaluate the lhs of
> > > MODIFY_EXPR after rhs, so conceptually this patch makes sense.
> >
> > Thank you both for taking a look.
> >
> > > But I wonder why we do in ubsan_maybe_instrument_array_ref:
> > > if (e != NULL_TREE)
> > > {
> > > tree t = copy_node (*expr_p);
> > > TREE_OPERAND (t, 1) = build2 (COMPOUND_EXPR, TREE_TYPE (op1),
> > > e, op1);
> > > *expr_p = t;
> > > }
> > > rather than modification of the ARRAY_REF's operand in place. If we
> > > did that, we wouldn't really care about the order, shared tree would
> > > be instrumented once, with SAVE_EXPR in there making sure we don't
> > > compute that multiple times. Is that because the 2 copies could
> > > have side-effects and we do want to evaluate those multiple times?
> >
> > I'd assumed that that was the point of the copy_node. But now that
> > I'm actually experimenting with it, I can't trigger any problems
> > without the copy_node. So maybe we can use the following patch, which
> > also adds a new test, bounds-21.c, to check that side-effects are
> > evaluated correctly. I didn't bother writing a description for this
> > patch yet because I sort of think we should apply both patches at the
> > same time.
>
> Perhaps it would be safer to apply for GCC 13 just your first patch
> and maybe the testsuite coverage from this one and defer this change
> for GCC 14?
That sounds good, I'll push the original patch with the new test now.
Thanks.
> > Regtested on x86_64-pc-linux-gnu.
> >
> > -- >8 --
> > PR sanitizer/108060
> > PR sanitizer/109050
> >
> > gcc/c-family/ChangeLog:
> >
> > * c-ubsan.cc (ubsan_maybe_instrument_array_ref): Don't copy_node.
> >
> > gcc/testsuite/ChangeLog:
> >
> > * c-c++-common/ubsan/bounds-17.c: New test.
> > * c-c++-common/ubsan/bounds-18.c: New test.
> > * c-c++-common/ubsan/bounds-19.c: New test.
> > * c-c++-common/ubsan/bounds-20.c: New test.
> > * c-c++-common/ubsan/bounds-21.c: New test.
>
> Jakub
>
Marek
prev parent reply other threads:[~2023-03-10 18:09 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-08 21:09 [PATCH] " Marek Polacek
2023-03-09 8:12 ` Richard Biener
2023-03-09 8:44 ` Jakub Jelinek
2023-03-10 0:44 ` [PATCH v2] " Marek Polacek
2023-03-10 18:07 ` Jakub Jelinek
2023-03-10 18:09 ` Marek Polacek [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=ZAtycrmn2QE+zmG/@redhat.com \
--to=polacek@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jakub@redhat.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).