[Bug target/112112] Improper Arithmetic Type Conversion in s390x-linux-gnu-gcc

2023-12-14 Thread xry111 at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112112

Xi Ruoyao  changed:

   What|Removed |Added

 CC||xry111 at gcc dot gnu.org
 Status|WAITING |RESOLVED
 Resolution|--- |DUPLICATE

--- Comment #10 from Xi Ruoyao  ---
Dup of a QEMU bug.

*** This bug has been marked as a duplicate of bug 112986 ***

[Bug target/112112] Improper Arithmetic Type Conversion in s390x-linux-gnu-gcc

2023-10-27 Thread 22s302h0659 at sonline20 dot sen.go.kr via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112112

--- Comment #4 from 김대영 <22s302h0659 at sonline20 dot sen.go.kr> ---
>From your perspective, do you think this could be a compiler bug? When tested
with various compiler options following the GCC bug reporting guidelines, the
binary compiles without any warnings, yet exhibits these behaviors

[Bug target/112112] Improper Arithmetic Type Conversion in s390x-linux-gnu-gcc

2023-10-29 Thread tkoenig at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112112

Thomas Koenig  changed:

   What|Removed |Added

 CC||tkoenig at gcc dot gnu.org

--- Comment #5 from Thomas Koenig  ---
(In reply to 김대영 from comment #4)
> From your perspective, do you think this could be a compiler bug? When
> tested with various compiler options following the GCC bug reporting
> guidelines, the binary compiles without any warnings, yet exhibits these
> behaviors

It definitely sounds wrong, there should be consistent results.

Just to make the effect of the signs clear: Could you maybe run the
program

$ cat a.c
#include 
SIGN char v1 = -1;
short v2 = 1;
int main()
{   
printf("result for " OPT " \"" STR "\" = %d\n", v1 <= v2);
return 0;
}

with the shell script

$ cat do_all.sh 
for s in signed unsigned ""
do
for o in -O0 -O1 -O2 -O3
do
gcc $o -DOPT='"'$o'"' -DSTR='"'$s'"' -DSIGN=$s a.c && ./a.out
done
done

and post the results?  For reference, on x86_64 (which has signed
chars) this gets

result for -O0 "signed" = 1
result for -O1 "signed" = 1
result for -O2 "signed" = 1
result for -O3 "signed" = 1
result for -O0 "unsigned" = 0
result for -O1 "unsigned" = 0
result for -O2 "unsigned" = 0
result for -O3 "unsigned" = 0
result for -O0 "" = 1
result for -O1 "" = 1
result for -O2 "" = 1
result for -O3 "" = 1

[Bug target/112112] Improper Arithmetic Type Conversion in s390x-linux-gnu-gcc

2023-10-30 Thread 22s302h0659 at sonline20 dot sen.go.kr via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112112

--- Comment #6 from 김대영 <22s302h0659 at sonline20 dot sen.go.kr> ---
```
z3rodae0@z3rodae0:~$ ./sh.sh
result for -O0 "signed" = 1
result for -O1 "signed" = 1
result for -O2 "signed" = 1
result for -O3 "signed" = 1
result for -O0 "unsigned" = 0
result for -O1 "unsigned" = 0
result for -O2 "unsigned" = 0
result for -O3 "unsigned" = 0
result for -O0 "" = 1
result for -O1 "" = 1
result for -O2 "" = 1
result for -O3 "" = 1
```

That's correct. I ran your code and script in my environment, and it produced
the same results

[Bug target/112112] Improper Arithmetic Type Conversion in s390x-linux-gnu-gcc

2023-11-01 Thread tkoenig at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112112

Thomas Koenig  changed:

   What|Removed |Added

   Last reconfirmed||2023-11-01
 Ever confirmed|0   |1
 Status|UNCONFIRMED |WAITING

--- Comment #7 from Thomas Koenig  ---
(In reply to 김대영 from comment #6)
> ```
> z3rodae0@z3rodae0:~$ ./sh.sh
> result for -O0 "signed" = 1
> result for -O1 "signed" = 1
> result for -O2 "signed" = 1
> result for -O3 "signed" = 1
> result for -O0 "unsigned" = 0
> result for -O1 "unsigned" = 0
> result for -O2 "unsigned" = 0
> result for -O3 "unsigned" = 0
> result for -O0 "" = 1
> result for -O1 "" = 1
> result for -O2 "" = 1
> result for -O3 "" = 1
> ```
> 
> That's correct. I ran your code and script in my environment, and it
> produced the same results

That is weird.

I don't see a meaningful difference between the version without signed or
unsigned and your program, and you get inconsistent results with your
original program and consistent results with the other one.

Or am I missing something?

[Bug target/112112] Improper Arithmetic Type Conversion in s390x-linux-gnu-gcc

2023-11-01 Thread 22s302h0659 at sonline20 dot sen.go.kr via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112112

--- Comment #8 from 김대영 <22s302h0659 at sonline20 dot sen.go.kr> ---
I'm sorry, I also didn't fully understand these bugs, my friend.

[Bug target/112112] Improper Arithmetic Type Conversion in s390x-linux-gnu-gcc

2023-11-10 Thread 22s302h0659 at sonline20 dot sen.go.kr via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112112

--- Comment #9 from 김대영 <22s302h0659 at sonline20 dot sen.go.kr> ---
```
#include 
#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
```