mirror of
https://github.com/frida/tinycc
synced 2025-01-06 12:02:09 +03:00
Futher changes to casts
nocode_wanted can't be used to enforce constant expressions, as it is set f.ex. by __builtin_constant_p. A null pointer is unequal to a pointer to any object or function. Assuming symbols always point to memory, a symbol+constant cast to bool is always true.
This commit is contained in:
parent
5fd6f7bd44
commit
76b02c2a03
9
tcc.c
9
tcc.c
@ -5975,7 +5975,7 @@ void force_charshort_cast(int t)
|
|||||||
/* cast 'vtop' to 'type'. Casting to bitfields is forbidden. */
|
/* cast 'vtop' to 'type'. Casting to bitfields is forbidden. */
|
||||||
static void gen_cast(CType *type)
|
static void gen_cast(CType *type)
|
||||||
{
|
{
|
||||||
int sbt, dbt, sf, df, c;
|
int sbt, dbt, sf, df, c, p;
|
||||||
|
|
||||||
/* special delayed cast for char/short */
|
/* special delayed cast for char/short */
|
||||||
/* XXX: in some cases (multiple cascaded casts), it may still
|
/* XXX: in some cases (multiple cascaded casts), it may still
|
||||||
@ -5997,6 +5997,7 @@ static void gen_cast(CType *type)
|
|||||||
sf = is_float(sbt);
|
sf = is_float(sbt);
|
||||||
df = is_float(dbt);
|
df = is_float(dbt);
|
||||||
c = (vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST;
|
c = (vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST;
|
||||||
|
p = (vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == (VT_CONST | VT_SYM);
|
||||||
if (c) {
|
if (c) {
|
||||||
/* constant case: we can do it now */
|
/* constant case: we can do it now */
|
||||||
/* XXX: in ISOC, cannot do it if error in convert */
|
/* XXX: in ISOC, cannot do it if error in convert */
|
||||||
@ -6053,6 +6054,9 @@ static void gen_cast(CType *type)
|
|||||||
vtop->c.i = ((int)vtop->c.ll << s) >> s;
|
vtop->c.i = ((int)vtop->c.ll << s) >> s;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (p && dbt == VT_BOOL) {
|
||||||
|
vtop->r = VT_CONST;
|
||||||
|
vtop->c.i = 1;
|
||||||
} else if (!nocode_wanted) {
|
} else if (!nocode_wanted) {
|
||||||
/* non constant case: generate code */
|
/* non constant case: generate code */
|
||||||
if (sf && df) {
|
if (sf && df) {
|
||||||
@ -6119,8 +6123,7 @@ static void gen_cast(CType *type)
|
|||||||
the lvalue already contains the real type size (see
|
the lvalue already contains the real type size (see
|
||||||
VT_LVAL_xxx constants) */
|
VT_LVAL_xxx constants) */
|
||||||
}
|
}
|
||||||
} else
|
}
|
||||||
expect("constant expression");
|
|
||||||
} else if ((dbt & VT_BTYPE) == VT_PTR && !(vtop->r & VT_LVAL)) {
|
} else if ((dbt & VT_BTYPE) == VT_PTR && !(vtop->r & VT_LVAL)) {
|
||||||
/* if we are casting between pointer types,
|
/* if we are casting between pointer types,
|
||||||
we must update the VT_LVAL_xxx size */
|
we must update the VT_LVAL_xxx size */
|
||||||
|
Loading…
Reference in New Issue
Block a user