public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "22s302h0659 at sonline20 dot sen.go.kr" <gcc-bugzilla@gcc.gnu.org> 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 [thread overview] Message-ID: <bug-112329-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112329 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=undefined -Wall -Wextra -fno-strict-aliasing -fwrapv s390x-linux-gnu-gcc ./bug_Poc.c -o test_O1 -I"/home/z3rodae0/csmith/include" -g -O1 -fsanitize=undefined -Wall -Wextra -fno-strict-aliasing -fwrapv s390x-linux-gnu-gcc ./bug_Poc.c -o test_O2 -I"/home/z3rodae0/csmith/include" -g -O2 -fsanitize=undefined -Wall -Wextra -fno-strict-aliasing -fwrapv s390x-linux-gnu-gcc ./bug_Poc.c -o test_O3 -I"/home/z3rodae0/csmith/include" -g -O3 -fsanitize=undefined -Wall -Wextra gcc ./bug_Poc.c -o gcc_O0 -I"/home/z3rodae0/csmith/include" -g -O0 -fsanitize=undefined -Wall -Wextra -fno-strict-aliasing -fwrapv gcc ./bug_Poc.c -o gcc_O1 -I"/home/z3rodae0/csmith/include" -g -O1 -fsanitize=undefined -Wall -Wextra -fno-strict-aliasing -fwrapv gcc ./bug_Poc.c -o gcc_O2 -I"/home/z3rodae0/csmith/include" -g -O2 -fsanitize=undefined -Wall -Wextra -fno-strict-aliasing -fwrapv gcc ./bug_Poc.c -o gcc_O3 -I"/home/z3rodae0/csmith/include" -g -O3 -fsanitize=undefined -Wall -Wextra -fno-strict-aliasing -fwrapv clang ./bug_Poc.c -o clang_O0 -I"/home/z3rodae0/csmith/include" -g -O0 -fsanitize=undefined -Wall -Wextra -fno-strict-aliasing -fwrapv clang ./bug_Poc.c -o clang_O1 -I"/home/z3rodae0/csmith/include" -g -O1 -fsanitize=undefined -Wall -Wextra -fno-strict-aliasing -fwrapv clang ./bug_Poc.c -o clang_O2 -I"/home/z3rodae0/csmith/include" -g -O2 -fsanitize=undefined -Wall -Wextra -fno-strict-aliasing -fwrapv clang ./bug_Poc.c -o clang_O3 -I"/home/z3rodae0/csmith/include" -g -O3 -fsanitize=undefined -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 <= 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 <stdio.h> 2 short g_14 = -1; 3 short g_89 = 1; 4 int main () 5 { 6 printf("bug== %d\n", ((unsigned char)(g_14)) <= g_89); 7 return 0; 8 } ``` ### Result ```bash bug== 0 bug== 0 bug== 1 bug== 1 bug== 0 bug== 0 bug== 0 bug== 0 bug== 0 bug== 0 bug== 0 bug== 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 version, 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 version poses a risk.
next reply other threads:[~2023-11-01 7:57 UTC|newest] Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-11-01 7:57 22s302h0659 at sonline20 dot sen.go.kr [this message] 2023-11-02 12:51 ` [Bug target/112329] Faulty arithmetic comparison in O2, O3 of s390x-gcc with -march=z13 xry111 at gcc dot gnu.org 2023-12-14 8:41 ` xry111 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-112329-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).