summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorherman ten brugge <hermantenbrugge@home.nl>2024-01-06 07:54:34 +0100
committerherman ten brugge <hermantenbrugge@home.nl>2024-01-06 07:54:34 +0100
commitc13bbb5cb584b136195a3be2ae6a8aee649ffe7b (patch)
treea343d7aaf6c88facf6b838c35746021ea99aa54a
parent6379f2ee76ac8d95c413f78b56e31a560e14ac6e (diff)
Add type promotion in comma expression and update testcase 94
-rw-r--r--tccgen.c9
-rw-r--r--tests/tests2/94_generic.c9
-rw-r--r--tests/tests2/94_generic.expect1
3 files changed, 16 insertions, 3 deletions
diff --git a/tccgen.c b/tccgen.c
index 29dae91..9a91c88 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 1cb0164..7ad9dd0 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 80d4ed9..79be7ab 100644
--- a/tests/tests2/94_generic.expect
+++ b/tests/tests2/94_generic.expect
@@ -13,3 +13,4 @@ long
1
3
5
+1