public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "jakub at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug sanitizer/108481] [10/11/12/13 Regression] UBsan missed a signed integer overflow
Date: Wed, 01 Feb 2023 13:11:22 +0000	[thread overview]
Message-ID: <bug-108481-4-GTaoCbysUA@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-108481-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108481

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to work|12.2.0                      |
            Summary|[13 Regression] UBsan       |[10/11/12/13 Regression]
                   |missed a signed integer     |UBsan missed a signed
                   |overflow                    |integer overflow
           Keywords|needs-bisection             |

--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Why is this marked 13 Regression?  I can certainly reproduce up to ~ r260000,
with just
-O1 -fsanitize=signed-integer-overflow so that I can use newer libubsan for
even older code back to r8-93-g2700fbd655f608e8e23.
The difference with r8-93 from earlier commits is that we decide to sink the
  i_15 = UBSAN_CHECK_SUB (i_9, 6822162149299574294);
statement, because the result of i isn't really used in the path when
j == 0.
We intentionally mark UBSAN_CHECK_SUB etc. internal functions as ECF_CONST, so
that they can be DCEd etc., we don't want to kill performance with
-fsanitize=undefined, if you don't care about performance of the code, just use
-O0 with -fsanitize=undefined.
So, similarly to how we don't diagnose
long
foo (long i)
{
  i = i - 6822162149299574294;
  return 0;
}

int
main ()
{
  return foo (-5354944485355449974);
}
at -O2 because the result of the subtraction isn't used, we allow the i = i -
6822162149299574294; subtraction to be sunk, so effectively:
@@ -11,8 +11,8 @@ static char f(int *g, short h, long i) {
     if ((i * (unsigned long)7 <= 1) << j)
       ;
     else {
-      i = i - 6822162149299574294;
       if (j) {
+        i = i - 6822162149299574294;
         if (*g)
           break;
         continue;
change in the source because for the return 8; path nothing cares about the
result.

I'd say this behaves as designed.

  parent reply	other threads:[~2023-02-01 13:11 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-20 14:17 [Bug sanitizer/108481] New: " shaohua.li at inf dot ethz.ch
2023-01-23 12:41 ` [Bug sanitizer/108481] " marxin at gcc dot gnu.org
2023-01-31  3:50 ` [Bug sanitizer/108481] [13 Regression] " pinskia at gcc dot gnu.org
2023-01-31  3:57 ` pinskia at gcc dot gnu.org
2023-01-31  4:00 ` pinskia at gcc dot gnu.org
2023-01-31  8:05 ` shaohua.li at inf dot ethz.ch
2023-02-01 13:11 ` jakub at gcc dot gnu.org [this message]
2023-02-01 13:16 ` [Bug sanitizer/108481] [10/11/12/13 " jakub at gcc dot gnu.org
2023-02-09 13:28 ` jakub at gcc dot gnu.org

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=bug-108481-4-GTaoCbysUA@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@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).