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
4444 static Sym *all_cleanups, *pending_gotos;
4545 static int local_scope;
4646 static int in_sizeof;
47+static int constant_p;
4748 ST_DATA char debug_modes;
4849
4950 ST_DATA SValue *vtop;
@@ -5567,8 +5568,10 @@ ST_FUNC void unary(void) · 5517 unmodified lines
55675568 }
55685569 break;
55695570 case TOK_builtin_constant_p:
5571+ constant_p = 1;
55705572 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 &&
55725575 !((vtop->r & VT_SYM) && vtop->sym->a.addrtaken);
55735576 vtop--;
55745577 vpushi(n);
@@ -6424,6 +6427,8 @@ ST_FUNC void gexpr(void) · 849 unmodified lines
64246427 expr_eq();
64256428 if (tok != ',')
64266429 break;
6430+ constant_p &= (vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST &&
6431+ !((vtop->r & VT_SYM) && vtop->sym->a.addrtaken);
64276432 vpop();
64286433 next();
64296434 }
tests/tcctest.c+1−0
@@ -3884,6 +3884,7 @@ void builtin_test(void) · 3883 unmodified lines
38843884 #endif
38853885 printf("res9 = %d\n", __builtin_constant_p("hi"));
38863886 printf("res10 = %d\n", __builtin_constant_p(func()));
3887+ printf("res11 = %d\n", __builtin_constant_p((i++, 7)));
38873888 s = 1;
38883889 ll = 2;
38893890 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