From c13bbb5cb584b136195a3be2ae6a8aee649ffe7b Mon Sep 17 00:00:00 2001 From: herman ten brugge Date: Sat, 6 Jan 2024 07:54:34 +0100 Subject: [PATCH] Add type promotion in comma expression and update testcase 94 --- tccgen.c | 9 ++++++--- tests/tests2/94_generic.c | 9 +++++++++ tests/tests2/94_generic.expect | 1 + 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/tccgen.c b/tccgen.c index 29dae91eb..9a91c882d 100644 --- a/tccgen.c +++ b/tccgen.c @@ -5876,9 +5876,7 @@ ST_FUNC void unary(void) next(); skip('('); expr_type(&controlling_type, expr_eq); - controlling_type.t &= ~(VT_CONSTANT | VT_VOLATILE | VT_ARRAY); - if ((controlling_type.t & VT_BTYPE) == VT_FUNC) - mk_pointer(&controlling_type); + convert_parameter_type (&controlling_type); nocode_wanted = saved_nocode_wanted; @@ -6547,12 +6545,17 @@ static void expr_eq(void) ST_FUNC void gexpr(void) { + int comma_found = 0; + while (1) { expr_eq(); + if (comma_found) + convert_parameter_type (&vtop->type); if (tok != ',') break; constant_p &= (vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST && !((vtop->r & VT_SYM) && vtop->sym->a.addrtaken); + comma_found = 1; vpop(); next(); } diff --git a/tests/tests2/94_generic.c b/tests/tests2/94_generic.c index 1cb016413..7ad9dd067 100644 --- a/tests/tests2/94_generic.c +++ b/tests/tests2/94_generic.c @@ -30,6 +30,12 @@ void void_foo(int i) {} typedef int int_type1; +typedef int T[4]; +int f(T t) +{ + return _Generic(t, __typeof__( ((void)0, (T){0}) ) : 1 ); +} + #define gen_sw(a) _Generic(a, const char *: 1, default: 8, int: 123); int main() @@ -40,6 +46,7 @@ int main() const int * const ptr; const char *ti; int_type1 i2; + T t; i = _Generic(a, int: a_f, const int: b_f)(); printf("%d\n", i); @@ -118,5 +125,7 @@ int main() (void)(sizeof(struct { int x:_Generic( 0?(int (*)[5])0 : ar, int (*)[5]:+1, int (*)[4]:(void)0); })); } + printf ("%d\n", f(t)); + return 0; } diff --git a/tests/tests2/94_generic.expect b/tests/tests2/94_generic.expect index 80d4ed9bd..79be7ab0f 100644 --- a/tests/tests2/94_generic.expect +++ b/tests/tests2/94_generic.expect @@ -13,3 +13,4 @@ long 1 3 5 +1