mirror of
https://github.com/mirror/tinycc.git
synced 2024-12-26 03:50:07 +08:00
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:
parent
2cb8bddd82
commit
96b31ba670
2
tccgen.c
2
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;
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user