From c9bbd4e7074fcb4f031bd207144e7283d658e518 Mon Sep 17 00:00:00 2001 From: herman ten brugge Date: Thu, 17 Sep 2020 09:11:10 +0200 Subject: [PATCH] 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 --- tccgen.c | 3 ++- tests/bug.c | 8 -------- tests/tcctest.c | 4 ++++ 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/tccgen.c b/tccgen.c index dd6a497a..0be3a52a 100644 --- a/tccgen.c +++ b/tccgen.c @@ -5701,7 +5701,8 @@ ST_FUNC void unary(void) break; case TOK_builtin_constant_p: parse_builtin_params(1, "e"); - n = (vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST; + n = (vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST && + !((vtop->r & VT_SYM) && vtop->sym->a.addrtaken); vtop--; vpushi(n); break; diff --git a/tests/bug.c b/tests/bug.c index 0778b57a..d4e61bcc 100644 --- a/tests/bug.c +++ b/tests/bug.c @@ -1,13 +1,6 @@ #include #include -void tst3(void) -{ - /* Should VT_SYM be checked for TOK_builtin_constant_p */ - int r = __builtin_constant_p("c"); - if (r == 0) printf("%d\n",r); -} - int compile_errors(void) { #if TEST == 1 @@ -45,5 +38,4 @@ int compile_errors(void) int main(void) { - tst3(); } diff --git a/tests/tcctest.c b/tests/tcctest.c index 0cf53a92..4696779d 100644 --- a/tests/tcctest.c +++ b/tests/tcctest.c @@ -3681,6 +3681,8 @@ void asm_test(void) int constant_p_var; +int func(void); + void builtin_test(void) { short s; @@ -3719,6 +3721,8 @@ void builtin_test(void) #else printf("res8 = %d\n", __builtin_constant_p(i && 0 ? i : 34)); #endif + printf("res9 = %d\n", __builtin_constant_p("hi")); + printf("res10 = %d\n", __builtin_constant_p(func())); s = 1; ll = 2; i = __builtin_choose_expr (1 != 0, ll, s);