<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/72018>72018</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [clang, gcc] Incorrect sign handling of char type in the s390x architecture.
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          z3rodae0
      </td>
    </tr>
</table>

<pre>
    ### Environment

- Compiler: clang-18 --target=s390x-linux-gnu (64bit)
- Version: Ubuntu clang version 14.0.0-1ubuntu1.1
- 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 clang s390x-linux-gnu (version 14.0.0) from it.

### Summary

I discovered a critical bug in various versions of the GCC and Clang compilers on the s390x architecture, where char types are treated as unsigned.

### Source Code

- **Version 1**

```bash
#include <stdio.h>
char v1 = -1;
short v2 = 1;
int main()
{   
    printf("bug = %d\n", v1 <= v2);
    return 0;
}
```

[[112112 – Improper Arithmetic Type Conversion in s390x-linux-gnu-gcc](https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112112)](https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112112)

The proof-of-concept code for the above bug is the same code I submitted when I initially reported this issue to GCC.

- **Version 2**

```c
#include <stdio.h>
#define M_1      0xad5d6da      /* 1010110101011101011011011010 */
char g_1 = -1;
short g_2 = -1;

char v1 = -1;
short v2 = 1;

int main(){
        char l_1 = -1;
        short l_2 = -1;
        printf("char g_1   = %d\n", g_1);
        printf("char l_1   = %d\n", l_1);
        printf("(char)M_1  = %d\n\n\n", (char)M_1);

        printf("short g_2  = %d\n", g_2);
        printf("short l_2  = %d\n", l_2);
        printf("(short)M_1 = %d\n\n\n", (short)M_1);

        printf("(char)-1 <= (short)1 = %s \n\n", (char)-1 <= (short)1 ? "True" : "False");

        printf("char v1    = %d\n", v1);
        printf("short  v2  = %d\n\n", v2);

        printf("v1 <= v2             = %s \n", v1 <= v2 ? "True" : "False");

        return 0;
}
```

The code above represents my exploration to understand the circumstances under which the bug occurs. I made various attempts with global variables, local variables, constant casting, etc. The output results vary depending on the optimization options O0, O1, O2, and O3.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysV8tu47gS_Rp6U5AgUZYfCy8Su30R4F7kAt3TvQwosixxhiIFPpzH1w9I2Ymd2N2ZxgiKEr4O6xRPFSvMOdlqxBWpb0m9mbDgO2NXL5U1gmExaYx4XhFajS980Xtpje5Re1JsSHEzfjNYm36QCi2pboArptusXECWeWZb9KTauGpZPGVK6vCUtToAoYvZtJGe0OUR4jtaJ42OCH80QfswAsF-7Idymhd5kZUhDZZ5eVz4f8X8ztg-rvwhtTCPDsryoc7LOl8WeZn1klvjzM5nzjMtmBXZj6__pcf1t0EqAfeDl718YT7uFRtGu4h4XxC6hvsyfWn6Vqfc70Bq55lSKMB3CO-ZemMU75jUEJzUbZpD6JwNntA5DIz_xVqEnmnWogWpj-SZFhC8VPIFxcETF5x47hxCl7Czpgfp81Mb3w7wa-h7Zp_PCQjpuNmjRQEMuJVecqagCW00Z8-sNMEdj8GB2SUO_1mvk43rZBo_nL8Do9_cAMzyTnrkPliMrnvs0CLwjlnwzwM6YBbBW2Q-7u0g6CRHcc16EyxHWBuB5_Ij9IbQm-9HZ4zNM4xZMb4Nc90rrNRcBYFAqrXzQpq8I9WXcTTZuC-BVBvISlLdjt2uM9bDnqb-t26pPfRMakIXr4om81sAGP8GABis1H6XZtDo24hAaC1IvdaEJmWl_dZxYE8jzhE-Lrfog9VQvHaS-eYdtzPCMZ5vy5KWJQXyhZJFQZYV3PWDNQNauLHSdz16yeHb8xB9qo9akvq90rKWc1JvCF103g8xLAjdErptOc9bHXJjW0K3TWhfpFKM0K3rzONDE9qct5JUWylItRltibT-PaQTwt86hMEas8vMLuNGcx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