From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id D7B6D3858C3A; Thu, 1 Feb 2024 09:35:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D7B6D3858C3A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1706780104; bh=XGa6o0KWfO7NLOnUGkLIILQmvObvbEtUbb2OURVDwSs=; h=From:To:Subject:Date:From; b=WEPERYo0WWxaoJTHVIscR1uOpLsBx6ZJemZabIqmtVBOCQnz/l8MbgKlkzeahxqP1 OGwuUymafgFYMe2cVhvuQIV/k5Sw6BPuuA2p2S6vPLnFD3Iw9E4yog9Tx6qfIeXB3c lIV6uDFln5kMz4dshTbCxrgdiXduG4gidZt2bYR8= From: "jiajing_zheng at 163 dot com" 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 12.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: jiajing_zheng at 163 dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D113702 Bug ID: 113702 Summary: -fsanitize=3Dundefined 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=3D57278&action=3Dedit 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=3Dundefined && ./a.out' at the -O0,-O1,-O2,-O3,-Os optimization le= vels 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=3Dundefined -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=3Dundefined -O0 && ./a.out', and it gav= e 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.=