aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Matz <matz@suse.de>2016-07-13 15:11:40 +0200
committerMichael Matz <matz@suse.de>2016-12-15 17:47:08 +0100
commit8a1a2a60336264a5f96fae4c7f02424c6928b7c3 (patch)
tree7c33a20e1ce519db9e5ce35b63817c1875a66b38
parent10e4db45dca082b6e936c5540d9f68156b3a8e79 (diff)
downloadtinycc-8a1a2a60336264a5f96fae4c7f02424c6928b7c3.tar.gz
tinycc-8a1a2a60336264a5f96fae4c7f02424c6928b7c3.tar.bz2
Implement __builtin_choose_expr
Follows GCC implementation.
-rw-r--r--tccgen.c29
-rw-r--r--tcctok.h1
-rw-r--r--tests/tcctest.c13
3 files changed, 43 insertions, 0 deletions
diff --git a/tccgen.c b/tccgen.c
index bbe1d83..c006f71 100644
--- a/tccgen.c
+++ b/tccgen.c
@@ -4238,6 +4238,35 @@ ST_FUNC void unary(void)
vpushi(is_compatible_types(&type1, &type2));
}
break;
+ case TOK_builtin_choose_expr:
+ {
+ int saved_nocode_wanted, c;
+ next();
+ skip('(');
+ c = expr_const();
+ skip(',');
+ if (!c) {
+ saved_nocode_wanted = nocode_wanted;
+ nocode_wanted = 1;
+ }
+ expr_eq();
+ if (!c) {
+ vpop();
+ nocode_wanted = saved_nocode_wanted;
+ }
+ skip(',');
+ if (c) {
+ saved_nocode_wanted = nocode_wanted;
+ nocode_wanted = 1;
+ }
+ expr_eq();
+ if (c) {
+ vpop();
+ nocode_wanted = saved_nocode_wanted;
+ }
+ skip(')');
+ }
+ break;
case TOK_builtin_constant_p:
{
int saved_nocode_wanted, res;
diff --git a/tcctok.h b/tcctok.h
index ec69908..9bbe879 100644
--- a/tcctok.h
+++ b/tcctok.h
@@ -132,6 +132,7 @@
DEF(TOK_VISIBILITY1, "visibility")
DEF(TOK_VISIBILITY2, "__visibility__")
DEF(TOK_builtin_types_compatible_p, "__builtin_types_compatible_p")
+ DEF(TOK_builtin_choose_expr, "__builtin_choose_expr")
DEF(TOK_builtin_constant_p, "__builtin_constant_p")
DEF(TOK_builtin_frame_address, "__builtin_frame_address")
DEF(TOK_builtin_return_address, "__builtin_return_address")
diff --git a/tests/tcctest.c b/tests/tcctest.c
index 57226f7..10033a4 100644
--- a/tests/tcctest.c
+++ b/tests/tcctest.c
@@ -2685,6 +2685,9 @@ int constant_p_var;
void builtin_test(void)
{
+ short s;
+ int i;
+ long long ll;
#if GCC_MAJOR >= 3
COMPAT_TYPE(int, int);
COMPAT_TYPE(int, unsigned int);
@@ -2704,6 +2707,16 @@ void builtin_test(void)
printf("res = %d\n", __builtin_constant_p(1 + 2));
printf("res = %d\n", __builtin_constant_p(&constant_p_var));
printf("res = %d\n", __builtin_constant_p(constant_p_var));
+ s = 1;
+ ll = 2;
+ i = __builtin_choose_expr (1 != 0, ll, s);
+ printf("bce: %d\n", i);
+ i = __builtin_choose_expr (1 != 1, ll, s);
+ printf("bce: %d\n", i);
+ i = sizeof (__builtin_choose_expr (1, ll, s));
+ printf("bce: %d\n", i);
+ i = sizeof (__builtin_choose_expr (0, ll, s));
+ printf("bce: %d\n", i);
}
#ifndef _WIN32