History

Make fn designators in ?: decay to ptrs

This _Generic((__typeof(1?f:f)*){0}, void (**)(void): (void)0); should compile like it does in gcc and clang.

Petr Skocik committed 7 years ago

Commit 49dfb571 parent 3058d412 files · +29 −5Browse files

Unified · Split

2 files
  1. tccgen.c +8 −5
  2. tests/tests2/33_ternary_op.c +21 −0
tccgen.c+8−5
@@ -5565,7 +5565,10 @@ static void expr_cond(void) · 5564 unmodified lines
55655565 if (!g)
55665566 gexpr();
55675567
5568− type1 = vtop->type;
5568+ if ( ((type1=vtop->type).t&VT_BTYPE)==VT_FUNC ) {
5569+ mk_pointer(&vtop->type);
5570+ type1=vtop->type;
5571+ }
55695572 sv = *vtop; /* save value to handle it later */
55705573 vtop--; /* no vpop so that FP stack is not flushed */
55715574 skip(':');
@@ -5583,7 +5586,10 @@ static void expr_cond(void) · 11 unmodified lines
55835586 if (c == 1)
55845587 nocode_wanted--;
55855588
5586− type2 = vtop->type;
5589+ if ( ((type2=vtop->type).t&VT_BTYPE)==VT_FUNC ) {
5590+ mk_pointer(&vtop->type);
5591+ type2=vtop->type;
5592+ }
55875593 t1 = type1.t;
55885594 bt1 = t1 & VT_BTYPE;
55895595 t2 = type2.t;
@@ -5643,9 +5649,6 @@ static void expr_cond(void) · 53 unmodified lines
56435649 0<pointed_type(&type1)->ref->c ?
56445650 pointed_type(&type1)->ref->c : pointed_type(&type2)->ref->c;
56455651 }
5646− } else if (bt1 == VT_FUNC || bt2 == VT_FUNC) {
5647− /* XXX: test function pointer compatibility */
5648− type = bt1 == VT_FUNC ? type1 : type2;
56495652 } else if (bt1 == VT_STRUCT || bt2 == VT_STRUCT) {
56505653 /* XXX: test structure compatibility */
56515654 type = bt1 == VT_STRUCT ? type1 : type2;
tests/tests2/33_ternary_op.c+21−0
@@ -1,6 +1,27 @@
11 #include <stdio.h>
22 #include <assert.h>
33
4+char arr[1];
5+static void f (void){}
6+void (*fp)(void) = f;
7+void call_fp()
8+{
9+ (fp?f:f)();
10+ (fp?fp:fp)();
11+ (fp?fp:&f)();
12+ (fp?&f:fp)();
13+ (fp?&f:&f)();
14+ _Generic(0?arr:arr, char*: (void)0);
15+ _Generic(0?&arr[0]:arr, char*: (void)0);
16+ _Generic(0?arr:&arr[0], char*: (void)0);
17+ _Generic(1?arr:arr, char*: (void)0);
18+ _Generic(1?&arr[0]:arr, char*: (void)0);
19+ _Generic(1?arr:&arr[0], char*: (void)0);
20+ _Generic((__typeof(1?f:f)*){0}, void (**)(void): (void)0);
21+ (fp?&f:f)();
22+ (fp?f:&f)();
23+}
24+
425 int main()
526 {
627 int Count;

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