forked from Mirrors/tinycc
optimized unary() - fix long long signed comparisons
parent
0adc5a8921
commit
ab9973c843
109
tcc.c
109
tcc.c
|
@ -4572,8 +4572,17 @@ void gen_opl(int op)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* compare low */
|
/* compare low. Always unsigned */
|
||||||
gen_op(op);
|
op1 = op;
|
||||||
|
if (op1 == TOK_LT)
|
||||||
|
op1 = TOK_ULT;
|
||||||
|
else if (op1 == TOK_LE)
|
||||||
|
op1 = TOK_ULE;
|
||||||
|
else if (op1 == TOK_GT)
|
||||||
|
op1 = TOK_UGT;
|
||||||
|
else if (op1 == TOK_GE)
|
||||||
|
op1 = TOK_UGE;
|
||||||
|
gen_op(op1);
|
||||||
a = gtst(1, a);
|
a = gtst(1, a);
|
||||||
gsym(b);
|
gsym(b);
|
||||||
vseti(VT_JMPI, a);
|
vseti(VT_JMPI, a);
|
||||||
|
@ -6109,32 +6118,48 @@ static void unary(void)
|
||||||
GFuncContext gf;
|
GFuncContext gf;
|
||||||
AttributeDef ad;
|
AttributeDef ad;
|
||||||
|
|
||||||
if (tok == TOK_CINT || tok == TOK_CCHAR || tok == TOK_LCHAR) {
|
/* XXX: GCC 2.95.3 does not generate a table although it should be
|
||||||
|
better here */
|
||||||
|
switch(tok) {
|
||||||
|
case TOK_CINT:
|
||||||
|
case TOK_CCHAR:
|
||||||
|
case TOK_LCHAR:
|
||||||
vpushi(tokc.i);
|
vpushi(tokc.i);
|
||||||
next();
|
next();
|
||||||
} else if (tok == TOK_CUINT) {
|
break;
|
||||||
|
case TOK_CUINT:
|
||||||
vpush_tokc(VT_INT | VT_UNSIGNED);
|
vpush_tokc(VT_INT | VT_UNSIGNED);
|
||||||
next();
|
next();
|
||||||
} else if (tok == TOK_CLLONG) {
|
break;
|
||||||
|
case TOK_CLLONG:
|
||||||
vpush_tokc(VT_LLONG);
|
vpush_tokc(VT_LLONG);
|
||||||
next();
|
next();
|
||||||
} else if (tok == TOK_CULLONG) {
|
break;
|
||||||
|
case TOK_CULLONG:
|
||||||
vpush_tokc(VT_LLONG | VT_UNSIGNED);
|
vpush_tokc(VT_LLONG | VT_UNSIGNED);
|
||||||
next();
|
next();
|
||||||
} else if (tok == TOK_CFLOAT) {
|
break;
|
||||||
|
case TOK_CFLOAT:
|
||||||
vpush_tokc(VT_FLOAT);
|
vpush_tokc(VT_FLOAT);
|
||||||
next();
|
next();
|
||||||
} else if (tok == TOK_CDOUBLE) {
|
break;
|
||||||
|
case TOK_CDOUBLE:
|
||||||
vpush_tokc(VT_DOUBLE);
|
vpush_tokc(VT_DOUBLE);
|
||||||
next();
|
next();
|
||||||
} else if (tok == TOK_CLDOUBLE) {
|
break;
|
||||||
|
case TOK_CLDOUBLE:
|
||||||
vpush_tokc(VT_LDOUBLE);
|
vpush_tokc(VT_LDOUBLE);
|
||||||
next();
|
next();
|
||||||
} else if (tok == TOK___FUNC__ || (tok == TOK___FUNCTION__ && gnu_ext)) {
|
break;
|
||||||
|
case TOK___FUNCTION__:
|
||||||
|
if (!gnu_ext)
|
||||||
|
goto tok_identifier;
|
||||||
|
/* fall thru */
|
||||||
|
case TOK___FUNC__:
|
||||||
|
{
|
||||||
void *ptr;
|
void *ptr;
|
||||||
int len;
|
int len;
|
||||||
/* special function name identifier */
|
/* special function name identifier */
|
||||||
|
|
||||||
len = strlen(funcname) + 1;
|
len = strlen(funcname) + 1;
|
||||||
/* generate char[len] type */
|
/* generate char[len] type */
|
||||||
type.t = VT_BYTE;
|
type.t = VT_BYTE;
|
||||||
|
@ -6145,10 +6170,12 @@ static void unary(void)
|
||||||
ptr = section_ptr_add(data_section, len);
|
ptr = section_ptr_add(data_section, len);
|
||||||
memcpy(ptr, funcname, len);
|
memcpy(ptr, funcname, len);
|
||||||
next();
|
next();
|
||||||
} else if (tok == TOK_LSTR) {
|
}
|
||||||
|
break;
|
||||||
|
case TOK_LSTR:
|
||||||
t = VT_INT;
|
t = VT_INT;
|
||||||
goto str_init;
|
goto str_init;
|
||||||
} else if (tok == TOK_STR) {
|
case TOK_STR:
|
||||||
/* string parsing */
|
/* string parsing */
|
||||||
t = VT_BYTE;
|
t = VT_BYTE;
|
||||||
str_init:
|
str_init:
|
||||||
|
@ -6157,10 +6184,9 @@ static void unary(void)
|
||||||
type.t |= VT_ARRAY;
|
type.t |= VT_ARRAY;
|
||||||
memset(&ad, 0, sizeof(AttributeDef));
|
memset(&ad, 0, sizeof(AttributeDef));
|
||||||
decl_initializer_alloc(&type, &ad, VT_CONST, 2, 0, 0);
|
decl_initializer_alloc(&type, &ad, VT_CONST, 2, 0, 0);
|
||||||
} else {
|
break;
|
||||||
t = tok;
|
case '(':
|
||||||
next();
|
next();
|
||||||
if (t == '(') {
|
|
||||||
/* cast ? */
|
/* cast ? */
|
||||||
if (parse_btype(&type, &ad)) {
|
if (parse_btype(&type, &ad)) {
|
||||||
type_decl(&type, &ad, &n, TYPE_ABSTRACT);
|
type_decl(&type, &ad, &n, TYPE_ABSTRACT);
|
||||||
|
@ -6185,10 +6211,14 @@ static void unary(void)
|
||||||
gexpr();
|
gexpr();
|
||||||
skip(')');
|
skip(')');
|
||||||
}
|
}
|
||||||
} else if (t == '*') {
|
break;
|
||||||
|
case '*':
|
||||||
|
next();
|
||||||
unary();
|
unary();
|
||||||
indir();
|
indir();
|
||||||
} else if (t == '&') {
|
break;
|
||||||
|
case '&':
|
||||||
|
next();
|
||||||
unary();
|
unary();
|
||||||
/* functions names must be treated as function pointers,
|
/* functions names must be treated as function pointers,
|
||||||
except for unary '&' and sizeof. Since we consider that
|
except for unary '&' and sizeof. Since we consider that
|
||||||
|
@ -6200,7 +6230,9 @@ static void unary(void)
|
||||||
test_lvalue();
|
test_lvalue();
|
||||||
mk_pointer(&vtop->type);
|
mk_pointer(&vtop->type);
|
||||||
gaddrof();
|
gaddrof();
|
||||||
} else if (t == '!') {
|
break;
|
||||||
|
case '!':
|
||||||
|
next();
|
||||||
unary();
|
unary();
|
||||||
if ((vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST)
|
if ((vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST)
|
||||||
vtop->c.i = !vtop->c.i;
|
vtop->c.i = !vtop->c.i;
|
||||||
|
@ -6208,18 +6240,26 @@ static void unary(void)
|
||||||
vtop->c.i = vtop->c.i ^ 1;
|
vtop->c.i = vtop->c.i ^ 1;
|
||||||
else
|
else
|
||||||
vseti(VT_JMP, gtst(1, 0));
|
vseti(VT_JMP, gtst(1, 0));
|
||||||
} else if (t == '~') {
|
break;
|
||||||
|
case '~':
|
||||||
|
next();
|
||||||
unary();
|
unary();
|
||||||
vpushi(-1);
|
vpushi(-1);
|
||||||
gen_op('^');
|
gen_op('^');
|
||||||
} else if (t == '+') {
|
break;
|
||||||
|
case '+':
|
||||||
|
next();
|
||||||
/* in order to force cast, we add zero */
|
/* in order to force cast, we add zero */
|
||||||
unary();
|
unary();
|
||||||
if ((vtop->type.t & VT_BTYPE) == VT_PTR)
|
if ((vtop->type.t & VT_BTYPE) == VT_PTR)
|
||||||
error("pointer not accepted for unary plus");
|
error("pointer not accepted for unary plus");
|
||||||
vpushi(0);
|
vpushi(0);
|
||||||
gen_op('+');
|
gen_op('+');
|
||||||
} else if (t == TOK_SIZEOF || t == TOK_ALIGNOF) {
|
break;
|
||||||
|
case TOK_SIZEOF:
|
||||||
|
case TOK_ALIGNOF:
|
||||||
|
t = tok;
|
||||||
|
next();
|
||||||
if (tok == '(') {
|
if (tok == '(') {
|
||||||
parse_expr_type(&type);
|
parse_expr_type(&type);
|
||||||
} else {
|
} else {
|
||||||
|
@ -6230,14 +6270,25 @@ static void unary(void)
|
||||||
vpushi(size);
|
vpushi(size);
|
||||||
else
|
else
|
||||||
vpushi(align);
|
vpushi(align);
|
||||||
} else if (t == TOK_INC || t == TOK_DEC) {
|
break;
|
||||||
|
|
||||||
|
case TOK_INC:
|
||||||
|
case TOK_DEC:
|
||||||
|
t = tok;
|
||||||
|
next();
|
||||||
unary();
|
unary();
|
||||||
inc(0, t);
|
inc(0, t);
|
||||||
} else if (t == '-') {
|
break;
|
||||||
|
case '-':
|
||||||
|
next();
|
||||||
vpushi(0);
|
vpushi(0);
|
||||||
unary();
|
unary();
|
||||||
gen_op('-');
|
gen_op('-');
|
||||||
} else if (t == TOK_LAND && gnu_ext) {
|
break;
|
||||||
|
case TOK_LAND:
|
||||||
|
if (!gnu_ext)
|
||||||
|
goto tok_identifier;
|
||||||
|
next();
|
||||||
/* allow to take the address of a label */
|
/* allow to take the address of a label */
|
||||||
if (tok < TOK_UIDENT)
|
if (tok < TOK_UIDENT)
|
||||||
expect("label identifier");
|
expect("label identifier");
|
||||||
|
@ -6253,7 +6304,11 @@ static void unary(void)
|
||||||
vset(&s->type, VT_CONST | VT_SYM, 0);
|
vset(&s->type, VT_CONST | VT_SYM, 0);
|
||||||
vtop->sym = s;
|
vtop->sym = s;
|
||||||
next();
|
next();
|
||||||
} else {
|
break;
|
||||||
|
default:
|
||||||
|
tok_identifier:
|
||||||
|
t = tok;
|
||||||
|
next();
|
||||||
if (t < TOK_UIDENT)
|
if (t < TOK_UIDENT)
|
||||||
expect("identifier");
|
expect("identifier");
|
||||||
s = sym_find(t);
|
s = sym_find(t);
|
||||||
|
@ -6270,7 +6325,7 @@ static void unary(void)
|
||||||
vtop->sym = s;
|
vtop->sym = s;
|
||||||
vtop->c.ul = 0;
|
vtop->c.ul = 0;
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* post operations */
|
/* post operations */
|
||||||
|
|
Loading…
Reference in New Issue