History

Allow strings in __builtin_constant_p

tccgen.c: - Fix handling __builtin_constant_p tests/bug.c: - Remove tst3 tests/tcctest.c: - Add new tests for __builtin_constant_p

herman ten brugge committed 6 years ago

Commit c9bbd4e1 parent 4a16beb3 files · +6 −9Browse files

Unified · Split

3 files
  1. tccgen.c +2 −1
  2. tests/bug.c +0 −8
  3. tests/tcctest.c +4 −0
tccgen.c+2−1
@@ -5701,7 +5701,8 @@ ST_FUNC void unary(void) · 5700 unmodified lines
57015701 break;
57025702 case TOK_builtin_constant_p:
57035703 parse_builtin_params(1, "e");
5704− n = (vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST;
5704+ n = (vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST &&
5705+ !((vtop->r & VT_SYM) && vtop->sym->a.addrtaken);
57055706 vtop--;
57065707 vpushi(n);
57075708 break;
tests/bug.c+0−8
@@ -1,13 +1,6 @@
11 #include <stdio.h>
22 #include <stdarg.h>
33
4−void tst3(void)
5−{
6− /* Should VT_SYM be checked for TOK_builtin_constant_p */
7− int r = __builtin_constant_p("c");
8− if (r == 0) printf("%d\n",r);
9−}
10−
114 int compile_errors(void)
125 {
136 #if TEST == 1
@@ -45,5 +38,4 @@ int compile_errors(void) · 31 unmodified lines
4538 int
4639 main(void)
4740 {
48− tst3();
4941 }
tests/tcctest.c+4−0
@@ -3681,6 +3681,8 @@ void asm_test(void) · 3680 unmodified lines
36813681
36823682 int constant_p_var;
36833683
3684+int func(void);
3685+
36843686 void builtin_test(void)
36853687 {
36863688 short s;
@@ -3719,6 +3721,8 @@ void builtin_test(void) · 32 unmodified lines
37193721 #else
37203722 printf("res8 = %d\n", __builtin_constant_p(i && 0 ? i : 34));
37213723 #endif
3724+ printf("res9 = %d\n", __builtin_constant_p("hi"));
3725+ printf("res10 = %d\n", __builtin_constant_p(func()));
37223726 s = 1;
37233727 ll = 2;
37243728 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