public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug sanitizer/115793] New: signed integer overflow check missing at optimization levels -O2, -O3, and -Os
@ 2024-07-05  7:23 bic60176 at gmail dot com
  2024-07-17  1:35 ` [Bug sanitizer/115793] " bic60176 at gmail dot com
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: bic60176 at gmail dot com @ 2024-07-05  7:23 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 115793
           Summary: signed integer overflow check missing at optimization
                    levels -O2, -O3, and -Os
           Product: gcc
           Version: 14.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: sanitizer
          Assignee: unassigned at gcc dot gnu.org
          Reporter: bic60176 at gmail dot com
                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
  Target Milestone: ---

Created attachment 58593
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=58593&action=edit
testcase

OS: Ubuntu 22.04.3 LTS
We found a case that UBSAN not reporting signed integer overflow when compiling
with gcc-14.1.0 at optimization levels -O2, -O3, and -Os.

$ ../compiler-builds/gcc-14.1.0_build/bin/gcc -fsanitize=undefined
-fsanitize=address -g -lgcc_s -I/home/csmith/include/csmith-2.3.0 -O0
testcase.c -o exec

$ timeout 1s ./exec 2>exec.err
0
testcase.c:8:54: runtime error: signed integer overflow: 56506 * 42049 cannot
be represented in type 'int'

$ ../compiler-builds/gcc-14.1.0_build/bin/gcc -fsanitize=undefined
-fsanitize=address -g -lgcc_s -I/home/csmith/include/csmith-2.3.0 -O2
testcase.c -o exec

$ timeout 1s ./exec 2>exec.err
0

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

* [Bug sanitizer/115793] signed integer overflow check missing at optimization levels -O2, -O3, and -Os
  2024-07-05  7:23 [Bug sanitizer/115793] New: signed integer overflow check missing at optimization levels -O2, -O3, and -Os bic60176 at gmail dot com
@ 2024-07-17  1:35 ` bic60176 at gmail dot com
  2024-07-17  4:00 ` xry111 at gcc dot gnu.org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: bic60176 at gmail dot com @ 2024-07-17  1:35 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Bi6c <bic60176 at gmail dot com> ---
When compiling with gcc-13.2.0 at -O0, -O1, -O2, -O3, and -Os, UBSAN reported
signed integer overflow error.
We wonder if the code was optimized out because of optimization level -O2, -O3,
and -Os in gcc-14.

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

* [Bug sanitizer/115793] signed integer overflow check missing at optimization levels -O2, -O3, and -Os
  2024-07-05  7:23 [Bug sanitizer/115793] New: signed integer overflow check missing at optimization levels -O2, -O3, and -Os bic60176 at gmail dot com
  2024-07-17  1:35 ` [Bug sanitizer/115793] " bic60176 at gmail dot com
@ 2024-07-17  4:00 ` xry111 at gcc dot gnu.org
  2024-07-19  2:15 ` bic60176 at gmail dot com
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: xry111 at gcc dot gnu.org @ 2024-07-17  4:00 UTC (permalink / raw)
  To: gcc-bugs

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

Xi Ruoyao <xry111 at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |xry111 at gcc dot gnu.org

--- Comment #2 from Xi Ruoyao <xry111 at gcc dot gnu.org> ---
Hmm I remember there's an opening bug report for this but I cannot find it...

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

* [Bug sanitizer/115793] signed integer overflow check missing at optimization levels -O2, -O3, and -Os
  2024-07-05  7:23 [Bug sanitizer/115793] New: signed integer overflow check missing at optimization levels -O2, -O3, and -Os bic60176 at gmail dot com
  2024-07-17  1:35 ` [Bug sanitizer/115793] " bic60176 at gmail dot com
  2024-07-17  4:00 ` xry111 at gcc dot gnu.org
@ 2024-07-19  2:15 ` bic60176 at gmail dot com
  2024-07-19  7:42 ` xry111 at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: bic60176 at gmail dot com @ 2024-07-19  2:15 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Bi6c <bic60176 at gmail dot com> ---
(In reply to Xi Ruoyao from comment #2)
> Hmm I remember there's an opening bug report for this but I cannot find it...

Is this considered a duplicated bug?

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

* [Bug sanitizer/115793] signed integer overflow check missing at optimization levels -O2, -O3, and -Os
  2024-07-05  7:23 [Bug sanitizer/115793] New: signed integer overflow check missing at optimization levels -O2, -O3, and -Os bic60176 at gmail dot com
                   ` (2 preceding siblings ...)
  2024-07-19  2:15 ` bic60176 at gmail dot com
@ 2024-07-19  7:42 ` xry111 at gcc dot gnu.org
  2024-07-22  7:51 ` bic60176 at gmail dot com
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: xry111 at gcc dot gnu.org @ 2024-07-19  7:42 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Xi Ruoyao <xry111 at gcc dot gnu.org> ---
(In reply to Bi6c from comment #3)
> (In reply to Xi Ruoyao from comment #2)
> > Hmm I remember there's an opening bug report for this but I cannot find it...
> 
> Is this considered a duplicated bug?

If we can find that duplicate... Or maybe my memory is just broken.

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

* [Bug sanitizer/115793] signed integer overflow check missing at optimization levels -O2, -O3, and -Os
  2024-07-05  7:23 [Bug sanitizer/115793] New: signed integer overflow check missing at optimization levels -O2, -O3, and -Os bic60176 at gmail dot com
                   ` (3 preceding siblings ...)
  2024-07-19  7:42 ` xry111 at gcc dot gnu.org
@ 2024-07-22  7:51 ` bic60176 at gmail dot com
  2024-07-22  9:45 ` jakub at gcc dot gnu.org
  2024-07-22 15:59 ` pinskia at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: bic60176 at gmail dot com @ 2024-07-22  7:51 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Bi6c <bic60176 at gmail dot com> ---
gcc-trunk also not reporting signed integer overflow at -O2, -O3, and -Os
(https://godbolt.org/z/8xnq1bo7s).

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

* [Bug sanitizer/115793] signed integer overflow check missing at optimization levels -O2, -O3, and -Os
  2024-07-05  7:23 [Bug sanitizer/115793] New: signed integer overflow check missing at optimization levels -O2, -O3, and -Os bic60176 at gmail dot com
                   ` (4 preceding siblings ...)
  2024-07-22  7:51 ` bic60176 at gmail dot com
@ 2024-07-22  9:45 ` jakub at gcc dot gnu.org
  2024-07-22 15:59 ` pinskia at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2024-07-22  9:45 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
This bugreport is based on the unwarranted assumption that UBSAN reports all UB
even at higher optimization levels.  It doesn't, that is part of the tradeoff
between code speed and amount of reported issues.  We don't report all the UB
in clearly dead code even at -O0, here VRP simply figures out that the
multiplication result would be
  # RANGE [irange] int [-INF, +INF] MASK 0xe441 VALUE 0x8d9f133a
  _2 = .UBSAN_CHECK_MUL (56506, 42049);
and because that result is only used in (_2 & 65534) == 0 comparison, that
comparison is folded to 0 and so the multiplication is optimized away.
With e.g. -O2 -fsanitize=undefined, one generally gets diagnosed UB that will
still happen in the program, which won't be DCEd.

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

* [Bug sanitizer/115793] signed integer overflow check missing at optimization levels -O2, -O3, and -Os
  2024-07-05  7:23 [Bug sanitizer/115793] New: signed integer overflow check missing at optimization levels -O2, -O3, and -Os bic60176 at gmail dot com
                   ` (5 preceding siblings ...)
  2024-07-22  9:45 ` jakub at gcc dot gnu.org
@ 2024-07-22 15:59 ` pinskia at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-07-22 15:59 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
.

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

end of thread, other threads:[~2024-07-22 15:59 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-07-05  7:23 [Bug sanitizer/115793] New: signed integer overflow check missing at optimization levels -O2, -O3, and -Os bic60176 at gmail dot com
2024-07-17  1:35 ` [Bug sanitizer/115793] " bic60176 at gmail dot com
2024-07-17  4:00 ` xry111 at gcc dot gnu.org
2024-07-19  2:15 ` bic60176 at gmail dot com
2024-07-19  7:42 ` xry111 at gcc dot gnu.org
2024-07-22  7:51 ` bic60176 at gmail dot com
2024-07-22  9:45 ` jakub at gcc dot gnu.org
2024-07-22 15:59 ` pinskia 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).