diff --git a/tccgen.c b/tccgen.c index 86ced00c..863d6a4d 100644 --- a/tccgen.c +++ b/tccgen.c @@ -930,9 +930,11 @@ static void vset_VT_JMP(void) int op = vtop->cmp_op; if (vtop->jtrue || vtop->jfalse) { + int origt = vtop->type.t; /* we need to jump to 'mov $0,%R' or 'mov $1,%R' */ int inv = op & (op < 2); /* small optimization */ vseti(VT_JMP+inv, gvtst(inv, 0)); + vtop->type.t = origt; } else { /* otherwise convert flags (rsp. 0/1) to register */ vtop->c.i = op; diff --git a/tests/tcctest.c b/tests/tcctest.c index 5f5783de..f9df38ab 100644 --- a/tests/tcctest.c +++ b/tests/tcctest.c @@ -1265,6 +1265,10 @@ void bool_test() printf("exp=%d\n", f == (32 <= a && a <= 3)); printf("r=%d\n", (t || f) + (t && f)); + /* check that types of casted &&/|| are preserved (here the unsignedness) */ + t = 1; + printf("type of bool: %d\n", (int) ( (~ ((unsigned int) (t && 1))) / 2) ); + /* test ? : cast */ { int aspect_on;