mirror of
https://github.com/frida/tinycc
synced 2024-11-24 08:39:37 +03:00
Implement __builtin_choose_expr
Follows GCC implementation.
This commit is contained in:
parent
10e4db45dc
commit
8a1a2a6033
29
tccgen.c
29
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;
|
||||
|
1
tcctok.h
1
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")
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user