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/112112] New: Improper Arithmetic Type Conversion in s390x-linux-gnu-gcc
Date: Sat, 28 Oct 2023 03:12:25 +0000	[thread overview]
Message-ID: <bug-112112-4@http.gcc.gnu.org/bugzilla/> (raw)

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112112

            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 <stdio.h>
3 char v1 = -1;
4 short v2 = 1;
5 int main()
6 {   
7     printf("bug = %d\n", v1 <= v2);
8     return 0;
9 }
```

```bash
// result
bug_O0 = 0
bug_O1 = 0
bug_O2 = 1
bug_O3 = 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 <stdio.h>
3 char v1 = -1;
4 short v2 = 1;
5 int main()
6 {   
7     printf("bug = %d\n", v1 >= v2);
8     return 0;
9 }
```

```bash
// result
bug_O0 = 1
bug_O1 = 1
bug_O2 = 0
bug_O3 = 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 correctly
returns 0. 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 0.

### Coclusion

The commonality in the two bug code examples above appears to be the treatment
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.

             reply	other threads:[~2023-10-28  3:12 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-28  3:12 22s302h0659 at sonline20 dot sen.go.kr [this message]
2023-10-28  3:22 ` [Bug c/112112] " 22s302h0659 at sonline20 dot sen.go.kr
2023-10-28  3:26 ` pinskia at gcc dot gnu.org
2023-10-28  6:20 ` pinskia at gcc dot gnu.org
2023-10-28  6:32 ` [Bug target/112112] " 22s302h0659 at sonline20 dot sen.go.kr
2023-10-29  9:06 ` tkoenig at gcc dot gnu.org
2023-10-31  2:32 ` 22s302h0659 at sonline20 dot sen.go.kr
2023-11-01  9:16 ` tkoenig at gcc dot gnu.org
2023-11-01 11:28 ` 22s302h0659 at sonline20 dot sen.go.kr
2023-11-10 10:24 ` 22s302h0659 at sonline20 dot sen.go.kr
2023-12-14  8:42 ` 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-112112-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: link
Be 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).