public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "pinskia at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug sanitizer/108481] [13 Regression] UBsan missed a signed integer overflow
Date: Tue, 31 Jan 2023 04:00:58 +0000	[thread overview]
Message-ID: <bug-108481-4-584m1V3NBY@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

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #2)
>       i = i - 6822162149299574294;
> 
> Is not being invoked on the executable code.
> 
> If we look at look at the original code:
> 
> 
>     if ((i * (unsigned long)7 <= 1) << j)
>       ;
>     else {
>       i = i - 6822162149299574294;
>       if (j) {
>         if (*g)
>           break;
>         continue;
>       }
>       return 8;
>     }
> ...
>   return h;
> 
> The only path where the undefined behavior even matters is inside the path
> that had continue in it. Which is where the subtraction is pushed to now.
> 
> I don't know if we should declear this as a valid thing to do or not.

This is what the IR looks in the end:
  _27 = _17 << _20;
  if (_27 != 0)
    goto <bb 12>; [50.00%]
  else
    goto <bb 9>; [50.00%]

  <bb 9> [local count: 1560331071]:
  if (_20 != 0)
    goto <bb 10>; [94.50%]
  else
    goto <bb 13>; [5.50%]

  <bb 10> [local count: 1474512859]:
  _30 = a;
  if (_30 != 0)
    goto <bb 13>; [67.00%]
  else
    goto <bb 11>; [33.00%]

  <bb 11> [local count: 486589241]:
  i_28 = .UBSAN_CHECK_SUB (i_13, 6822162149299574294);

  <bb 12> [local count: 2046920311]:
  # i_34 = PHI <i_13(8), i_28(11)>
  (Loop back)
...

  <bb 13> [local count: 1073741830]:
  return 0;

As you can see the only path where the ubsan_check_sub is executed is right
before the continue which is seems like a very valid thing to do.

  parent reply	other threads:[~2023-01-31  4:00 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 [this message]
2023-01-31  8:05 ` shaohua.li at inf dot ethz.ch
2023-02-01 13:11 ` [Bug sanitizer/108481] [10/11/12/13 " jakub at gcc dot gnu.org
2023-02-01 13:16 ` 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-584m1V3NBY@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).