From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 5C03A385352D; Sat, 28 Oct 2023 03:12:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5C03A385352D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1698462745; bh=QN5tHw1Rs/VICTyuDwp50mY7XC9yuWqfGOOBrw3lsik=; h=From:To:Subject:Date:From; b=xbaWqos1DBGZo8PxOWTxlugGVzFlEYjnHAfujCWbxOin3nMkfoSHVjZ7KpK47udTw VErkL4esfel8gLYdPEYgxyMVL+aYXDZ7VS0Y6WZGKj0hBHwyywq9ISSpOCliwW3hOZ wwCxq5px1DrZc3G/5B68HdGI+mXy7J5+5iqS9ozQ= From: "22s302h0659 at sonline20 dot sen.go.kr" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/112112] New: Improper Arithmetic Type Conversion in s390x-linux-gnu-gcc Date: Sat, 28 Oct 2023 03:12:25 +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=3D112112 Bug ID: 112112 Summary: Improper Arithmetic Type Conversion in s390x-linux-gnu-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. ### Summary Using the legacy C code generator 'csmith' to generate test cases, I am performing fuzzing on the GCC compiler for various architectures and optimization options. I have discovered a bug specific to the s390x architecture, and I will be reporting it. ### Source Code I have prepared an 'binarys.zip' archive containing two versions of the bug= PoC code, along with '[c.sh](http://c.sh/)' for compiling them and '[r.sh](http://r.sh/)' for running them ```bash 1 // bug_Poc1.c 2 #include 3 char v1 =3D -1; 4 short v2 =3D 1; 5 int main() 6 {=20=20=20 7 printf("bug =3D %d\n", v1 <=3D v2); 8 return 0; 9 } ``` ```bash // result bug_O0 =3D 0 bug_O1 =3D 0 bug_O2 =3D 1 bug_O3 =3D 1 ``` Line 7 yields a correct result of 1 for the normal comparison operation. However, with the O0 and O1 optimization options, it returns 0. With O2 and= O3, it correctly returns 1. I conducted tests to confirm the possibility of this bug occurring in cross-compilers for the same version but different architectures, but it consistently output the correct value of 1. ```bash 1 // bug_Poc2.c 2 #include 3 char v1 =3D -1; 4 short v2 =3D 1; 5 int main() 6 {=20=20=20 7 printf("bug =3D %d\n", v1 >=3D v2); 8 return 0; 9 } ``` ```bash // result bug_O0 =3D 1 bug_O1 =3D 1 bug_O2 =3D 0 bug_O3 =3D 0 ``` On the 7th line, the normal comparison operation results in 0. However, with the O0 and O1 optimization options, it returns 01. With O2 and O3, it corre= ctly returns 0. I conducted tests to confirm the possibility of this bug occurri= ng in cross-compilers for the same version but different architectures, but it consistently output the correct value of 0. ### Coclusion The commonality in the two bug code examples above appears to be the treatm= ent of -1 as unsigned rather than signed. My suspicion is that there might be an issue with the integer arithmetic types or instructions on the s390x architecture.=