1
0
Fork 0

Fix casted boolean expressions

the casted type was lost when a delayed bool was finally converted
to a value.  See testcase, in the wrong case the '(unsigned int)' cast
was ignored, and hence the division was signed reulting in -1 instead of
the proper 0x7fffffff.
This commit is contained in:
Michael Matz 2023-03-10 16:49:27 +01:00
parent 2cb8bddd82
commit 96b31ba670
2 changed files with 6 additions and 0 deletions

View File

@ -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;

View File

@ -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;