public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Richard Biener <rguenther@suse.de>
Cc: gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] middle-end/108995 - avoid folding when sanitizing overflow
Date: Thu, 9 Mar 2023 14:10:10 +0100	[thread overview]
Message-ID: <ZAnastIWWgNG4L59@tucnak> (raw)
In-Reply-To: <20230308093849.51C183858C62@sourceware.org>

On Wed, Mar 08, 2023 at 09:38:43AM +0000, Richard Biener via Gcc-patches wrote:
> The following plugs one place in extract_muldiv where it should avoid
> folding when sanitizing overflow.
> 
> I'm unsure about the testcase, I didn't find any that tests for
> a runtime sanitizer error ...
> 
> Bootstrapped and tested on x86_64-unknown-linux-gnu.
> 
> OK?
> 
> 	PR middle-end/108995
> 	* fold-const.cc (extract_muldiv_1): Avoid folding
> 	(CST * b) / CST2 when sanitizing overflow and we rely on
> 	overflow being undefined.

This is ok.

> 
> 	* gcc.dg/ubsan/pr108995.c: New testcase.

As for testcase, there are many testcases that test for runtime sanitizer
errors.  For ubsan, it is more common to test -fsanitize-recover= and
just dg-output scan the output for expected diagnostics (many examples
in that directory).
Another possibility is to test for the no recovery, see e.g.
gcc.dg/ubsan/bounds-3.c.  In that case there should be
/* { dg-do run } */
and
/* { dg-shouldfail "ubsan" } */
but dg-output checking for the exact wording is still highly desirable.

The test also relies on 32-bit ints, so it should be dg-do run { target int32 }
I think.

> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/ubsan/pr108995.c
> @@ -0,0 +1,15 @@
> +/* { dg-do run { xfail *-*-* } } */
> +/* With optimization we constant fold and diagnose the overflow and do
> +   not sanitize anything.  */
> +/* { dg-skip-if "" { *-*-* } { "*" } { ! "-O0" } } */
> +/* { dg-options "-fsanitize=undefined -fno-sanitize-recover=undefined" } */
> +
> +int a;
> +const int b = 44514;
> +int *c = &a;
> +
> +int main ()
> +{
> +  *c = 65526 * b / 6;
> +  return 0;
> +}
> -- 
> 2.35.3

	Jakub


       reply	other threads:[~2023-03-09 13:10 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20230308093849.51C183858C62@sourceware.org>
2023-03-09 13:10 ` Jakub Jelinek [this message]
2023-03-09 13:29   ` Richard Biener
2023-03-08  9:38 Richard Biener

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=ZAnastIWWgNG4L59@tucnak \
    --to=jakub@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --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).