History

Add type promotion in comma expression and update testcase 94

herman ten brugge committed 2 years ago

Commit c13bbb51 parent 6379f2e3 files · +16 −3Browse files

Unified · Split

3 files
  1. tccgen.c +6 −3
  2. tests/tests2/94_generic.c +9 −0
  3. tests/tests2/94_generic.expect +1 −0
tccgen.c+6−3
@@ -5876,9 +5876,7 @@ ST_FUNC void unary(void) · 5875 unmodified lines
5876 next();5876 next();
5877 skip('(');5877 skip('(');
5878 expr_type(&controlling_type, expr_eq);5878 expr_type(&controlling_type, expr_eq);
5879 controlling_type.t &= ~(VT_CONSTANT | VT_VOLATILE | VT_ARRAY);5879 convert_parameter_type (&controlling_type);
5880 if ((controlling_type.t & VT_BTYPE) == VT_FUNC)
5881 mk_pointer(&controlling_type);
5882 5880
5883 nocode_wanted = saved_nocode_wanted;5881 nocode_wanted = saved_nocode_wanted;
5884 5882
@@ -6547,12 +6545,17 @@ static void expr_eq(void) · 662 unmodified lines
6547 6545
6548ST_FUNC void gexpr(void)6546ST_FUNC void gexpr(void)
6549{6547{
6548 int comma_found = 0;
6549
6550 while (1) {6550 while (1) {
6551 expr_eq();6551 expr_eq();
6552 if (comma_found)
6553 convert_parameter_type (&vtop->type);
6552 if (tok != ',')6554 if (tok != ',')
6553 break;6555 break;
6554 constant_p &= (vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST &&6556 constant_p &= (vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST &&
6555 !((vtop->r & VT_SYM) && vtop->sym->a.addrtaken);6557 !((vtop->r & VT_SYM) && vtop->sym->a.addrtaken);
6558 comma_found = 1;
6556 vpop();6559 vpop();
6557 next();6560 next();
6558 }6561 }
tests/tests2/94_generic.c+9−0
@@ -30,6 +30,12 @@ void void_foo(int i) {} · 29 unmodified lines
30 30
31typedef int int_type1;31typedef int int_type1;
32 32
33typedef int T[4];
34int f(T t)
35{
36 return _Generic(t, __typeof__( ((void)0, (T){0}) ) : 1 );
37}
38
33#define gen_sw(a) _Generic(a, const char *: 1, default: 8, int: 123);39#define gen_sw(a) _Generic(a, const char *: 1, default: 8, int: 123);
34 40
35int main()41int main()
@@ -40,6 +46,7 @@ int main() · 4 unmodified lines
40 const int * const ptr;46 const int * const ptr;
41 const char *ti;47 const char *ti;
42 int_type1 i2;48 int_type1 i2;
49 T t;
43 50
44 i = _Generic(a, int: a_f, const int: b_f)();51 i = _Generic(a, int: a_f, const int: b_f)();
45 printf("%d\n", i);52 printf("%d\n", i);
@@ -118,5 +125,7 @@ int main() · 72 unmodified lines
118 (void)(sizeof(struct { int x:_Generic( 0?(int (*)[5])0 : ar, int (*)[5]:+1, int (*)[4]:(void)0); }));125 (void)(sizeof(struct { int x:_Generic( 0?(int (*)[5])0 : ar, int (*)[5]:+1, int (*)[4]:(void)0); }));
119 }126 }
120 127
128 printf ("%d\n", f(t));
129
121 return 0;130 return 0;
122}131}
tests/tests2/94_generic.expect+1−0
@@ -13,3 +13,4 @@ long · 12 unmodified lines
131131
143143
155155
161

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t