public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug sanitizer/108481] New: UBsan missed a signed integer overflow
@ 2023-01-20 14:17 shaohua.li at inf dot ethz.ch
  2023-01-23 12:41 ` [Bug sanitizer/108481] " marxin at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: shaohua.li at inf dot ethz.ch @ 2023-01-20 14:17 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 108481
           Summary: UBsan missed a signed integer overflow
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: sanitizer
          Assignee: unassigned at gcc dot gnu.org
          Reporter: shaohua.li at inf dot ethz.ch
                CC: dodji at gcc dot gnu.org, dvyukov at gcc dot gnu.org,
                    jakub at gcc dot gnu.org, kcc at gcc dot gnu.org, marxin at gcc dot gnu.org
  Target Milestone: ---

For the following code, UBsan at -O1 and above missed the signed integer
overflow, while -O0 found it. I checked the assembly and the buggy code was not
optimized away.

Clang detected it at all optimization levels.

Compiler explorer: https://godbolt.org/z/rK6sad1WG

%cat a.c
int a, d;
short b;
short *c = &b;
int *const e = &d;
static char f(int *g, short h, long i) {
  d = 2;
  for (;; d--) {
    int j = *e;
    *g = (0 || h) / h;
    *c = 3;
    if ((i * (unsigned long)7 <= 1) << j)
      ;
    else {
      i = i - 6822162149299574294;
      if (j) {
        if (*g)
          break;
        continue;
      }
      return 8;
    }
  }
  return h;
}
int main() {
  int *k = &a;
  f(k, 4, 8289379813243698614);
}
%
%gcc-tk -fsanitize=undefined -O1 && ./a.out
%
%gcc-tk -fsanitize=undefined -O0 && ./a.out
/a.c:14:9: runtime error: signed integer overflow: -5354944485355449974 -
6822162149299574294 cannot be represented in type 'long int'
%

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2023-02-09 13:28 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-20 14:17 [Bug sanitizer/108481] New: UBsan missed a signed integer overflow 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 ` [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

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).