public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/112329] New: Faulty arithmetic comparison in O2, O3 of s390x-gcc
@ 2023-11-01 7:57 22s302h0659 at sonline20 dot sen.go.kr
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
0 siblings, 2 replies; 3+ messages in thread
From: 22s302h0659 at sonline20 dot sen.go.kr @ 2023-11-01 7:57 UTC (permalink / raw)
To: gcc-bugs
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.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug target/112329] Faulty arithmetic comparison in O2, O3 of s390x-gcc with -march=z13
2023-11-01 7:57 [Bug c/112329] New: Faulty arithmetic comparison in O2, O3 of s390x-gcc 22s302h0659 at sonline20 dot sen.go.kr
@ 2023-11-02 12:51 ` xry111 at gcc dot gnu.org
2023-12-14 8:41 ` xry111 at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: xry111 at gcc dot gnu.org @ 2023-11-02 12:51 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112329
Xi Ruoyao <xry111 at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |xry111 at gcc dot gnu.org
Summary|Faulty arithmetic |Faulty arithmetic
|comparison in O2, O3 of |comparison in O2, O3 of
|s390x-gcc |s390x-gcc with -march=z13
--- Comment #1 from Xi Ruoyao <xry111 at gcc dot gnu.org> ---
Ubuntu is configuring their s390x GCC --with-arch=z13 and it seems -march=z13
is needed for reproduce the issue with vanilla GCC.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug target/112329] Faulty arithmetic comparison in O2, O3 of s390x-gcc with -march=z13
2023-11-01 7:57 [Bug c/112329] New: Faulty arithmetic comparison in O2, O3 of s390x-gcc 22s302h0659 at sonline20 dot sen.go.kr
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
1 sibling, 0 replies; 3+ messages in thread
From: xry111 at gcc dot gnu.org @ 2023-12-14 8:41 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112329
Xi Ruoyao <xry111 at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |DUPLICATE
--- Comment #2 from Xi Ruoyao <xry111 at gcc dot gnu.org> ---
Dup of a QEMU bug.
*** This bug has been marked as a duplicate of bug 112986 ***
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-12-14 8:41 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-01 7:57 [Bug c/112329] New: Faulty arithmetic comparison in O2, O3 of s390x-gcc 22s302h0659 at sonline20 dot sen.go.kr
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
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).