* [Bug c/112112] Improper Arithmetic Type Conversion in s390x-linux-gnu-gcc
2023-10-28 3:12 [Bug c/112112] New: Improper Arithmetic Type Conversion in s390x-linux-gnu-gcc 22s302h0659 at sonline20 dot sen.go.kr
@ 2023-10-28 3:22 ` 22s302h0659 at sonline20 dot sen.go.kr
2023-10-28 3:26 ` pinskia at gcc dot gnu.org
` (8 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: 22s302h0659 at sonline20 dot sen.go.kr @ 2023-10-28 3:22 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112112
--- Comment #1 from 김대영 <22s302h0659 at sonline20 dot sen.go.kr> ---
Created attachment 56320
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=56320&action=edit
bug_Poc Codes.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c/112112] Improper Arithmetic Type Conversion in s390x-linux-gnu-gcc
2023-10-28 3:12 [Bug c/112112] New: Improper Arithmetic Type Conversion in s390x-linux-gnu-gcc 22s302h0659 at sonline20 dot sen.go.kr
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
` (7 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-10-28 3:26 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112112
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
One thing you should note (most likely not an issue here) is that plain char
can default to signed or unsigned depending on the arch/abi .
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c/112112] Improper Arithmetic Type Conversion in s390x-linux-gnu-gcc
2023-10-28 3:12 [Bug c/112112] New: Improper Arithmetic Type Conversion in s390x-linux-gnu-gcc 22s302h0659 at sonline20 dot sen.go.kr
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
` (6 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-10-28 6:20 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112112
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 112111 has been marked as a duplicate of this bug. ***
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug target/112112] Improper Arithmetic Type Conversion in s390x-linux-gnu-gcc
2023-10-28 3:12 [Bug c/112112] New: Improper Arithmetic Type Conversion in s390x-linux-gnu-gcc 22s302h0659 at sonline20 dot sen.go.kr
` (2 preceding siblings ...)
2023-10-28 6:20 ` pinskia at gcc dot gnu.org
@ 2023-10-28 6:32 ` 22s302h0659 at sonline20 dot sen.go.kr
2023-10-29 9:06 ` tkoenig at gcc dot gnu.org
` (5 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: 22s302h0659 at sonline20 dot sen.go.kr @ 2023-10-28 6:32 UTC (permalink / raw)
To: 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
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug target/112112] Improper Arithmetic Type Conversion in s390x-linux-gnu-gcc
2023-10-28 3:12 [Bug c/112112] New: Improper Arithmetic Type Conversion in s390x-linux-gnu-gcc 22s302h0659 at sonline20 dot sen.go.kr
` (3 preceding siblings ...)
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
` (4 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: tkoenig at gcc dot gnu.org @ 2023-10-29 9:06 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112112
Thomas Koenig <tkoenig at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |tkoenig at gcc dot gnu.org
--- Comment #5 from Thomas Koenig <tkoenig at gcc dot gnu.org> ---
(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 <stdio.h>
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
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug target/112112] Improper Arithmetic Type Conversion in s390x-linux-gnu-gcc
2023-10-28 3:12 [Bug c/112112] New: Improper Arithmetic Type Conversion in s390x-linux-gnu-gcc 22s302h0659 at sonline20 dot sen.go.kr
` (4 preceding siblings ...)
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
` (3 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: 22s302h0659 at sonline20 dot sen.go.kr @ 2023-10-31 2:32 UTC (permalink / raw)
To: 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
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug target/112112] Improper Arithmetic Type Conversion in s390x-linux-gnu-gcc
2023-10-28 3:12 [Bug c/112112] New: Improper Arithmetic Type Conversion in s390x-linux-gnu-gcc 22s302h0659 at sonline20 dot sen.go.kr
` (5 preceding siblings ...)
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
` (2 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: tkoenig at gcc dot gnu.org @ 2023-11-01 9:16 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112112
Thomas Koenig <tkoenig at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2023-11-01
Ever confirmed|0 |1
Status|UNCONFIRMED |WAITING
--- Comment #7 from Thomas Koenig <tkoenig at gcc dot gnu.org> ---
(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?
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug target/112112] Improper Arithmetic Type Conversion in s390x-linux-gnu-gcc
2023-10-28 3:12 [Bug c/112112] New: Improper Arithmetic Type Conversion in s390x-linux-gnu-gcc 22s302h0659 at sonline20 dot sen.go.kr
` (6 preceding siblings ...)
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
9 siblings, 0 replies; 11+ messages in thread
From: 22s302h0659 at sonline20 dot sen.go.kr @ 2023-11-01 11:28 UTC (permalink / raw)
To: 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.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug target/112112] Improper Arithmetic Type Conversion in s390x-linux-gnu-gcc
2023-10-28 3:12 [Bug c/112112] New: Improper Arithmetic Type Conversion in s390x-linux-gnu-gcc 22s302h0659 at sonline20 dot sen.go.kr
` (7 preceding siblings ...)
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
9 siblings, 0 replies; 11+ messages in thread
From: 22s302h0659 at sonline20 dot sen.go.kr @ 2023-11-10 10:24 UTC (permalink / raw)
To: gcc-bugs
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
```
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug target/112112] Improper Arithmetic Type Conversion in s390x-linux-gnu-gcc
2023-10-28 3:12 [Bug c/112112] New: Improper Arithmetic Type Conversion in s390x-linux-gnu-gcc 22s302h0659 at sonline20 dot sen.go.kr
` (8 preceding siblings ...)
2023-11-10 10:24 ` 22s302h0659 at sonline20 dot sen.go.kr
@ 2023-12-14 8:42 ` xry111 at gcc dot gnu.org
9 siblings, 0 replies; 11+ messages in thread
From: xry111 at gcc dot gnu.org @ 2023-12-14 8:42 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112112
Xi Ruoyao <xry111 at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |xry111 at gcc dot gnu.org
Status|WAITING |RESOLVED
Resolution|--- |DUPLICATE
--- Comment #10 from Xi Ruoyao <xry111 at gcc dot gnu.org> ---
Dup of a QEMU bug.
*** This bug has been marked as a duplicate of bug 112986 ***
^ permalink raw reply [flat|nested] 11+ messages in thread