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

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