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.
Unified · Split
| @@ -44,6 +44,7 @@ static int nb_sym_pools; · 43 unmodified lines | |||
| 44 | static Sym *all_cleanups, *pending_gotos; | 44 | static Sym *all_cleanups, *pending_gotos; |
| 45 | static int local_scope; | 45 | static int local_scope; |
| 46 | static int in_sizeof; | 46 | static int in_sizeof; |
| 47 | static int constant_p; | ||
| 47 | ST_DATA char debug_modes; | 48 | ST_DATA char debug_modes; |
| 48 | 49 | ||
| 49 | ST_DATA SValue *vtop; | 50 | ST_DATA SValue *vtop; |
| @@ -5567,8 +5568,10 @@ ST_FUNC void unary(void) · 5517 unmodified lines | |||
| 5567 | } | 5568 | } |
| 5568 | break; | 5569 | break; |
| 5569 | case TOK_builtin_constant_p: | 5570 | case TOK_builtin_constant_p: |
| 5571 | constant_p = 1; | ||
| 5570 | parse_builtin_params(1, "e"); | 5572 | parse_builtin_params(1, "e"); |
| 5571 | n = (vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST && | 5573 | n = constant_p && |
| 5574 | (vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST && | ||
| 5572 | !((vtop->r & VT_SYM) && vtop->sym->a.addrtaken); | 5575 | !((vtop->r & VT_SYM) && vtop->sym->a.addrtaken); |
| 5573 | vtop--; | 5576 | vtop--; |
| 5574 | vpushi(n); | 5577 | vpushi(n); |
| @@ -6424,6 +6427,8 @@ ST_FUNC void gexpr(void) · 849 unmodified lines | |||
| 6424 | expr_eq(); | 6427 | expr_eq(); |
| 6425 | if (tok != ',') | 6428 | if (tok != ',') |
| 6426 | break; | 6429 | break; |
| 6430 | constant_p &= (vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST && | ||
| 6431 | !((vtop->r & VT_SYM) && vtop->sym->a.addrtaken); | ||
| 6427 | vpop(); | 6432 | vpop(); |
| 6428 | next(); | 6433 | next(); |
| 6429 | } | 6434 | } |
| @@ -3884,6 +3884,7 @@ void builtin_test(void) · 3883 unmodified lines | |||
| 3884 | #endif | 3884 | #endif |
| 3885 | printf("res9 = %d\n", __builtin_constant_p("hi")); | 3885 | printf("res9 = %d\n", __builtin_constant_p("hi")); |
| 3886 | printf("res10 = %d\n", __builtin_constant_p(func())); | 3886 | printf("res10 = %d\n", __builtin_constant_p(func())); |
| 3887 | printf("res11 = %d\n", __builtin_constant_p((i++, 7))); | ||
| 3887 | s = 1; | 3888 | s = 1; |
| 3888 | ll = 2; | 3889 | ll = 2; |
| 3889 | i = __builtin_choose_expr (1 != 0, ll, s); | 3890 | i = __builtin_choose_expr (1 != 0, ll, s); |