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
5701 break;5701 break;
5702 case TOK_builtin_constant_p:5702 case TOK_builtin_constant_p:
5703 parse_builtin_params(1, "e");5703 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);
5705 vtop--;5706 vtop--;
5706 vpushi(n);5707 vpushi(n);
5707 break;5708 break;
tests/bug.c+0−8
@@ -1,13 +1,6 @@
1#include <stdio.h>1#include <stdio.h>
2#include <stdarg.h>2#include <stdarg.h>
3 3
4void 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
11int compile_errors(void)4int compile_errors(void)
12{5{
13#if TEST == 16#if TEST == 1
@@ -45,5 +38,4 @@ int compile_errors(void) · 31 unmodified lines
45int38int
46main(void)39main(void)
47{40{
48 tst3();
49}41}
tests/tcctest.c+4−0
@@ -3681,6 +3681,8 @@ void asm_test(void) · 3680 unmodified lines
3681 3681
3682int constant_p_var;3682int constant_p_var;
3683 3683
3684int func(void);
3685
3684void builtin_test(void)3686void builtin_test(void)
3685{3687{
3686 short s;3688 short s;
@@ -3719,6 +3721,8 @@ void builtin_test(void) · 32 unmodified lines
3719#else3721#else
3720 printf("res8 = %d\n", __builtin_constant_p(i && 0 ? i : 34));3722 printf("res8 = %d\n", __builtin_constant_p(i && 0 ? i : 34));
3721#endif3723#endif
3724 printf("res9 = %d\n", __builtin_constant_p("hi"));
3725 printf("res10 = %d\n", __builtin_constant_p(func()));
3722 s = 1;3726 s = 1;
3723 ll = 2;3727 ll = 2;
3724 i = __builtin_choose_expr (1 != 0, ll, s);3728 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