From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 115B13858D28; Wed, 1 Nov 2023 07:57:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 115B13858D28 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1698825436; bh=5Z45OlvgdmtWt7aTDHUixyk6wVDSF/5vmCOLGKv+X9Q=; h=From:To:Subject:Date:From; b=AVqjVFTlMxqO0Q/XXOQoxSXz1gwBmyCslfc5Shb+GBRmXgjnkcdV6kAp+GerL8p1e NB1MUswRtS3IfXEB9jDnYfmZdiePg+n6jSJu9RtyT7VVm55RjqFRW1YqxPC9upctiR MaufByU11VaLDYbmhPF0xR34RWSBRbpdZWqJwW9w= From: "22s302h0659 at sonline20 dot sen.go.kr" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/112329] New: Faulty arithmetic comparison in O2, O3 of s390x-gcc Date: Wed, 01 Nov 2023 07:57:15 +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: 11.4.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: 22s302h0659 at sonline20 dot sen.go.kr 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 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=3D112329 Bug ID: 112329 Summary: Faulty arithmetic comparison in O2, O3 of s390x-gcc Product: gcc Version: 11.4.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: 22s302h0659 at sonline20 dot sen.go.kr Target Milestone: --- ### Environment - Compiler: s390x-linux-gnu-gcc (64bit) - Version: gcc version 11.4.0 (Ubuntu 11.4.0-1ubuntu1~22.04) - Platform: Windows 11_5.15.90.1-microsoft-standard-WSL2 - Build Optimization Options: O0, O1, O2, O3 I installed the s390x-linux-gnu toolchain using the 'apt' package manager in Ubuntu and utilized s390x-linux-gnu-gcc (version 11.4.0) from it. ### build script & excution script ```bash # build scripts s390x-linux-gnu-gcc ./bug_Poc.c -o test_O0 -I"/home/z3rodae0/csmith/include= " -g -O0 -fsanitize=3Dundefined -Wall -Wextra -fno-strict-aliasing -fwrapv s390x-linux-gnu-gcc ./bug_Poc.c -o test_O1 -I"/home/z3rodae0/csmith/include= " -g -O1 -fsanitize=3Dundefined -Wall -Wextra -fno-strict-aliasing -fwrapv s390x-linux-gnu-gcc ./bug_Poc.c -o test_O2 -I"/home/z3rodae0/csmith/include= " -g -O2 -fsanitize=3Dundefined -Wall -Wextra -fno-strict-aliasing -fwrapv s390x-linux-gnu-gcc ./bug_Poc.c -o test_O3 -I"/home/z3rodae0/csmith/include= " -g -O3 -fsanitize=3Dundefined -Wall -Wextra gcc ./bug_Poc.c -o gcc_O0 -I"/home/z3rodae0/csmith/include" -g -O0 -fsanitize=3Dundefined -Wall -Wextra -fno-strict-aliasing -fwrapv gcc ./bug_Poc.c -o gcc_O1 -I"/home/z3rodae0/csmith/include" -g -O1 -fsanitize=3Dundefined -Wall -Wextra -fno-strict-aliasing -fwrapv gcc ./bug_Poc.c -o gcc_O2 -I"/home/z3rodae0/csmith/include" -g -O2 -fsanitize=3Dundefined -Wall -Wextra -fno-strict-aliasing -fwrapv gcc ./bug_Poc.c -o gcc_O3 -I"/home/z3rodae0/csmith/include" -g -O3 -fsanitize=3Dundefined -Wall -Wextra -fno-strict-aliasing -fwrapv clang ./bug_Poc.c -o clang_O0 -I"/home/z3rodae0/csmith/include" -g -O0 -fsanitize=3Dundefined -Wall -Wextra -fno-strict-aliasing -fwrapv clang ./bug_Poc.c -o clang_O1 -I"/home/z3rodae0/csmith/include" -g -O1 -fsanitize=3Dundefined -Wall -Wextra -fno-strict-aliasing -fwrapv clang ./bug_Poc.c -o clang_O2 -I"/home/z3rodae0/csmith/include" -g -O2 -fsanitize=3Dundefined -Wall -Wextra -fno-strict-aliasing -fwrapv clang ./bug_Poc.c -o clang_O3 -I"/home/z3rodae0/csmith/include" -g -O3 -fsanitize=3Dundefined -Wall -Wextra -fno-strict-aliasing -fwrapv ``` ```bash # run scripts qemu-s390x-static -L /usr/s390x-linux-gnu/ ./test_O0 qemu-s390x-static -L /usr/s390x-linux-gnu/ ./test_O1 qemu-s390x-static -L /usr/s390x-linux-gnu/ ./test_O2 qemu-s390x-static -L /usr/s390x-linux-gnu/ ./test_O3 ./gcc_O0 ./gcc_O1 ./gcc_O2 ./gcc_O3 ./clang_O0 ./clang_O1 ./clang_O2 ./clang_O3 ``` When casting the negative value -1 to an unsigned char at the 6th line, it becomes the value 255. Then, comparing it with g_89, the expression 255 <= =3D 1 is false, so it is correct to return 0. However, with optimization options O2,= O3, it returns the value 1. ### Source Code ```c 1 #include 2 short g_14 =3D -1; 3 short g_89 =3D 1; 4 int main () 5 {=20 6 printf("bug=3D=3D %d\n", ((unsigned char)(g_14)) <=3D g_89);=20 7 return 0; 8 } ``` ### Result ```bash bug=3D=3D 0 bug=3D=3D 0 bug=3D=3D 1 bug=3D=3D 1 bug=3D=3D 0 bug=3D=3D 0 bug=3D=3D 0 bug=3D=3D 0 bug=3D=3D 0 bug=3D=3D 0 bug=3D=3D 0 bug=3D=3D 0 ``` ### Coclusion I'm reporting this issue due to incorrect results in integer comparison operations. I've reported bugs twice before that occurred in the s390x architecture. Although the cross-compiler I'm using is not the latest versi= on, I consider this to be quite important. This is because most people install = the cross-compiler via 'apt install', so incorrect code generation in this vers= ion poses a risk.=