diff --git a/tccgen.c b/tccgen.c index d02e4b12..72ac7742 100644 --- a/tccgen.c +++ b/tccgen.c @@ -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 */ } } diff --git a/tests/bug.c b/tests/bug.c index 7ec44109..67614afe 100644 --- a/tests/bug.c +++ b/tests/bug.c @@ -1,14 +1,6 @@ #include #include -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(); } diff --git a/tests/tests2/117_gcc_test.c b/tests/tests2/117_gcc_test.c index aed62e24..8b0467fc 100644 --- a/tests/tests2/117_gcc_test.c +++ b/tests/tests2/117_gcc_test.c @@ -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(); }