History

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.

herman ten brugge committed 3 years ago

Commit afcdaf11 parent 747ad402 files · +7 −1Browse files

Unified · Split

2 files
  1. tccgen.c +6 −1
  2. tests/tcctest.c +1 −0
tccgen.c+6−1
@@ -44,6 +44,7 @@ static int nb_sym_pools; · 43 unmodified lines
44static Sym *all_cleanups, *pending_gotos;44static Sym *all_cleanups, *pending_gotos;
45static int local_scope;45static int local_scope;
46static int in_sizeof;46static int in_sizeof;
47static int constant_p;
47ST_DATA char debug_modes;48ST_DATA char debug_modes;
48 49
49ST_DATA SValue *vtop;50ST_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 }
tests/tcctest.c+1−0
@@ -3884,6 +3884,7 @@ void builtin_test(void) · 3883 unmodified lines
3884#endif3884#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);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t