Skip to content

Commit

Permalink
Add type promotion in comma expression and update testcase 94
Browse files Browse the repository at this point in the history
  • Loading branch information
hermantb committed Jan 6, 2024
1 parent 6379f2e commit c13bbb5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
9 changes: 6 additions & 3 deletions tccgen.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
}
Expand Down
9 changes: 9 additions & 0 deletions tests/tests2/94_generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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);
Expand Down Expand Up @@ -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;
}
1 change: 1 addition & 0 deletions tests/tests2/94_generic.expect
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ long
1
3
5
1

0 comments on commit c13bbb5

Please sign in to comment.