tccgen.c: - Fix handling __builtin_constant_p tests/bug.c: - Remove tst3 tests/tcctest.c: - Add new tests for __builtin_constant_p
Unified · Split
| @@ -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; |
| @@ -1,13 +1,6 @@ | |||
| 1 | #include <stdio.h> | 1 | #include <stdio.h> |
| 2 | #include <stdarg.h> | 2 | #include <stdarg.h> |
| 3 | 3 | ||
| 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 | |||
| 11 | int compile_errors(void) | 4 | int compile_errors(void) |
| 12 | { | 5 | { |
| 13 | #if TEST == 1 | 6 | #if TEST == 1 |
| @@ -45,5 +38,4 @@ int compile_errors(void) · 31 unmodified lines | |||
| 45 | int | 38 | int |
| 46 | main(void) | 39 | main(void) |
| 47 | { | 40 | { |
| 48 | tst3(); | ||
| 49 | } | 41 | } |
| @@ -3681,6 +3681,8 @@ void asm_test(void) · 3680 unmodified lines | |||
| 3681 | 3681 | ||
| 3682 | int constant_p_var; | 3682 | int constant_p_var; |
| 3683 | 3683 | ||
| 3684 | int func(void); | ||
| 3685 | |||
| 3684 | void builtin_test(void) | 3686 | void builtin_test(void) |
| 3685 | { | 3687 | { |
| 3686 | short s; | 3688 | short s; |
| @@ -3719,6 +3721,8 @@ void builtin_test(void) · 32 unmodified lines | |||
| 3719 | #else | 3721 | #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 | #endif | 3723 | #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); |