Fix __builtin_constant_p with comma expression
See: https://savannah.nongnu.org/bugs/?58606 and: mpfr-4.1.1/tests/tcmp_ui.c The code '__builtin_constant_p ((i++, 7))' was not working. I Fixed it in tccgen.c I added a testcase in tests/tcctest.c. I also wanted to add a test like '__builtin_constant_p ((10, 7))' but gcc needs -O1 for that to work. clang (and now tcc) work as expected.
This commit is contained in:
parent
747ad409ac
commit
afcdaf121a
2 changed files with 7 additions and 1 deletions
7
tccgen.c
7
tccgen.c
|
@ -44,6 +44,7 @@ static int nb_sym_pools;
|
|||
static Sym *all_cleanups, *pending_gotos;
|
||||
static int local_scope;
|
||||
static int in_sizeof;
|
||||
static int constant_p;
|
||||
ST_DATA char debug_modes;
|
||||
|
||||
ST_DATA SValue *vtop;
|
||||
|
@ -5567,8 +5568,10 @@ ST_FUNC void unary(void)
|
|||
}
|
||||
break;
|
||||
case TOK_builtin_constant_p:
|
||||
constant_p = 1;
|
||||
parse_builtin_params(1, "e");
|
||||
n = (vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST &&
|
||||
n = constant_p &&
|
||||
(vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST &&
|
||||
!((vtop->r & VT_SYM) && vtop->sym->a.addrtaken);
|
||||
vtop--;
|
||||
vpushi(n);
|
||||
|
@ -6424,6 +6427,8 @@ ST_FUNC void gexpr(void)
|
|||
expr_eq();
|
||||
if (tok != ',')
|
||||
break;
|
||||
constant_p &= (vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST &&
|
||||
!((vtop->r & VT_SYM) && vtop->sym->a.addrtaken);
|
||||
vpop();
|
||||
next();
|
||||
}
|
||||
|
|
|
@ -3884,6 +3884,7 @@ void builtin_test(void)
|
|||
#endif
|
||||
printf("res9 = %d\n", __builtin_constant_p("hi"));
|
||||
printf("res10 = %d\n", __builtin_constant_p(func()));
|
||||
printf("res11 = %d\n", __builtin_constant_p((i++, 7)));
|
||||
s = 1;
|
||||
ll = 2;
|
||||
i = __builtin_choose_expr (1 != 0, ll, s);
|
||||
|
|
Loading…
Reference in a new issue