Fix char to ushort cast

tccgen.c:
- gen_cast: add check for char to ushort cast

tests/bug.c:
- remove tst1

tests/tests2/117_gcc_test.c:
- add tst_cast
This commit is contained in:
herman ten brugge 2020-08-21 19:35:30 +02:00
parent 696b765437
commit a34a9775ba
3 changed files with 13 additions and 9 deletions

View File

@ -3573,6 +3573,11 @@ again:
/* ss <= 4 here */
if (ds <= 4) {
gv(RC_INT);
if (ds == 2 && (dbt & VT_UNSIGNED) &&
ss == 1 && (sbt & VT_UNSIGNED) == 0) {
vpushi(0xffff);
gen_op('&');
}
goto done; /* no 64bit envolved */
}
}

View File

@ -1,14 +1,6 @@
#include <stdio.h>
#include <stdarg.h>
void tst1(void)
{
/* problem in gen_cast. Should mask unsigned types */
signed char c = (signed char) 0xffffffff;
int r = (unsigned short) c ^ (signed char) 0x99999999;
if (r != 0xffff0066) printf ("%x\n", r);
}
typedef struct{double x,y;}p;
void tst2(int n,...)
@ -69,7 +61,6 @@ int
main(void)
{
p v = { 1, 2};
tst1();
tst2(1, v);
tst3();
}

View File

@ -139,6 +139,13 @@ void tst_pack (void)
if (j.f != i.f) printf("error\n");
}
void tst_cast(void)
{
signed char c = (signed char) 0xaaaaaaaa;
int r = (unsigned short) c ^ (signed char) 0x99999999;
if (r != 0xffff0033) printf ("%x\n", r);
}
int
main (void)
{
@ -155,4 +162,5 @@ main (void)
tst_builtin();
tst_compare();
tst_pack();
tst_cast();
}