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

            Bug ID: 112986
           Summary: s390x gcc O2, O3: Incorrect logic operation in <
                    comparison with the same values
           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

```c
s390x-linux-gnu-gcc -o bug0 bug.c -O0 -fsanitize=undefined 
s390x-linux-gnu-gcc -o bug1 bug.c -O1 -fsanitize=undefined 
s390x-linux-gnu-gcc -o bug2 bug.c -O2 -fsanitize=undefined 
s390x-linux-gnu-gcc -o bug3 bug.c -O3 -fsanitize=undefined 
```

```c
qemu-s390x-static -L /usr/s390x-linux-gnu/ ./bug0
qemu-s390x-static -L /usr/s390x-linux-gnu/ ./bug1
qemu-s390x-static -L /usr/s390x-linux-gnu/ ./bug2
qemu-s390x-static -L /usr/s390x-linux-gnu/ ./bug3
```

This is the build script and the execution script.

# Source Code

```c
#include <stdio.h>

unsigned int g_2 = 1;
signed short g_70 = 1;

int main (int argc, char* argv[])
{
    printf("bug = %d\n", ((signed long long)g_2 < g_70));
    return 0;
}
```

In the s390x architecture, the '<' comparison operation for the same values
returns an incorrect logical value.

# output

```c
Expected output
O0: 0
O1: 0
O2: 0
O3: 0

Actual output
O0: 0
O1: 0
O2: 1
O3: 1
```

Reply via email to