public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "jiajing_zheng at 163 dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c/113702] New: -fsanitize=undefined missed a check under GCC 12.2.0 compared to 13.2.0 Date: Thu, 01 Feb 2024 09:35:03 +0000 [thread overview] Message-ID: <bug-113702-4@http.gcc.gnu.org/bugzilla/> (raw) 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.
next reply other threads:[~2024-02-01 9:35 UTC|newest] Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top 2024-02-01 9:35 jiajing_zheng at 163 dot com [this message] 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
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-113702-4@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: linkBe 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).