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

--- Comment #9 from κΉ€λŒ€μ˜ <22s302h0659 at sonline20 dot sen.go.kr> ---
```
#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;
}
```
I have been continuously investigating bugs recently. The above code proves
that it cannot reliably handle 'char' type as signed. Additionally, testing in
the s390x native environment with GCC versions 9, 11.4.0, and 12 consistently
revealed the same bug.

```
root@a92c2f395400:~# gcc -o test test.c -O0
root@a92c2f395400:~# ./test
char g_1   = 255
char l_1   = 255
(char)M_1  = 218


short g_2  = -1
short l_2  = -1
(short)M_1 = -10534


(char)-1 <= (short)1 = False

char v1    = 255
short  v2  = 1

v1 <= v2             = False
root@a92c2f395400:~# gcc -o test test.c -O2
root@a92c2f395400:~# ./test
char g_1   = 255
char l_1   = 255
(char)M_1  = 218


short g_2  = -1
short l_2  = -1
(short)M_1 = -10534


(char)-1 <= (short)1 = False

char v1    = 255
short  v2  = 1

v1 <= v2             = True
```

Reply via email to