public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/113702] New: -fsanitize=undefined missed a check under GCC 12.2.0 compared to 13.2.0
@ 2024-02-01  9:35 jiajing_zheng at 163 dot com
  2024-02-01  9:43 ` [Bug c/113702] " jiajing_zheng at 163 dot com
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: jiajing_zheng at 163 dot com @ 2024-02-01  9:35 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 113702
           Summary: -fsanitize=undefined missed a check under GCC 12.2.0
                    compared to 13.2.0
           Product: gcc
           Version: 12.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jiajing_zheng at 163 dot com
  Target Milestone: ---

Created attachment 57278
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=57278&action=edit
source C file causing the problem

I'm sorry, but I'm not sure which component causes this problem.

The sub expression '(int)(g_B * g_A[1])' in source.c has a signed overflow
problem. I checked the file using 'gcc source.c -fsanitize=undefined
<optimization level> && ./a.out' at the -O0,-O1,-O2,-O3,-Os optimization levels
under GCC12.2.0 and GCC13.2.0. The results showed that 'signed integer
overflow' was given under GCC13.2.0, but missed under GCC12.2.0.

I then compared the assembly parts of '(int)(g_B * g_A[1])' of the two GCC
versions at the -O0 level using 'gcc source.c -fsanitize=undefined -O0 -S'.

Under GCC13.2.0:
.L13:
        movzbl  g_A(%rip), %r12d
        movzbl  g_A+1(%rip), %eax
        movzbl  %al, %eax
        movl    g_B(%rip), %edx
        movl    %eax, %ebx
        imull   %edx, %ebx
        jno     .L3
        movslq  %edx, %rdx
        cltq
        movq    %rax, %rsi
        movl    $.Lubsan_data3, %edi
        call    __ubsan_handle_mul_overflow

Under GCC12.2.0:
.L11:
        movzbl  g_A(%rip), %edx
        movzbl  g_A+1(%rip), %eax
        movl    g_B(%rip), %ecx
        imull   %ecx, %eax

Under GCC12.2.0, it shows that it lacks overflow judgment after 'imul'
operation. So I modified the last line 'imull   %ecx, %eax ' to the follwing
lines that I expected:
        movl  %eax, %ebx
        imull   %ecx, %eax
        jno     .L20
        movslq  %ecx, %rdx
        cltq
        movq    %rbx, %rsi
        movl    $.Lubsan_data3, %edi
        call    __ubsan_handle_mul_overflow
.L20:

Then I run 'gcc source.s -fsanitize=undefined -O0 && ./a.out', and it gave the
expected 'signed integer overflow' message.

I wonder why GCC12.2.0 not perform overflow judgment after imull., and what
components of 13.2.0 were modified for this issue.

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

* [Bug c/113702] -fsanitize=undefined missed a check under GCC 12.2.0 compared to 13.2.0
  2024-02-01  9:35 [Bug c/113702] New: -fsanitize=undefined missed a check under GCC 12.2.0 compared to 13.2.0 jiajing_zheng at 163 dot com
@ 2024-02-01  9:43 ` jiajing_zheng at 163 dot com
  2024-02-01 10:01 ` xry111 at gcc dot gnu.org
  2024-02-01 10:02 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: jiajing_zheng at 163 dot com @ 2024-02-01  9:43 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Jiajing_Zheng <jiajing_zheng at 163 dot com> ---
jing@jing-ubuntu:~$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/home/jing/gcc-12.2.0/usr/local/bin/../libexec/gcc/x86_64-pc-linux-gnu/12.2.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../configure -enable-checking=release -enable-languages=c,c++
-disable-multilib
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 12.2.0 (GCC) 


jing@jing-ubuntu:~$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/home/jing/gcc-13.2.0-install/libexec/gcc/x86_64-pc-linux-gnu/13.2.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../configure --prefix=/home/jing/gcc-13.2.0-install
--enable-threads=posix -enable-checking=release -enable-languages=c,c++
-disable-multilib
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 13.2.0 (GCC)

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

* [Bug c/113702] -fsanitize=undefined missed a check under GCC 12.2.0 compared to 13.2.0
  2024-02-01  9:35 [Bug c/113702] New: -fsanitize=undefined missed a check under GCC 12.2.0 compared to 13.2.0 jiajing_zheng at 163 dot com
  2024-02-01  9:43 ` [Bug c/113702] " jiajing_zheng at 163 dot com
@ 2024-02-01 10:01 ` xry111 at gcc dot gnu.org
  2024-02-01 10:02 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: xry111 at gcc dot gnu.org @ 2024-02-01 10:01 UTC (permalink / raw)
  To: gcc-bugs

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

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> ---
With GCC 12 the expression is "optimized" early (already in original tree)
into:

g_A[0] = g_A[0] + (unsigned char) ((signed char) ((unsigned char) g_A[1] *
(unsigned char) g_B) & (signed char) (g_A[1] & g_A[0]) | (signed char) g_A[0])

and the optimization is arguably wrong (or at lease undesired) with sanitizer.

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

* [Bug c/113702] -fsanitize=undefined missed a check under GCC 12.2.0 compared to 13.2.0
  2024-02-01  9:35 [Bug c/113702] New: -fsanitize=undefined missed a check under GCC 12.2.0 compared to 13.2.0 jiajing_zheng at 163 dot com
  2024-02-01  9:43 ` [Bug c/113702] " jiajing_zheng at 163 dot com
  2024-02-01 10:01 ` xry111 at gcc dot gnu.org
@ 2024-02-01 10:02 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-02-01 10:02 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Dup of bug 108256. Yes a newer version of GCC fixed this.

*** This bug has been marked as a duplicate of bug 108256 ***

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

end of thread, other threads:[~2024-02-01 10:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-01  9:35 [Bug c/113702] New: -fsanitize=undefined missed a check under GCC 12.2.0 compared to 13.2.0 jiajing_zheng at 163 dot com
2024-02-01  9:43 ` [Bug c/113702] " jiajing_zheng at 163 dot com
2024-02-01 10:01 ` xry111 at gcc dot gnu.org
2024-02-01 10:02 ` 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).