Skip to content

Commit 90d1f7f

Browse files
committed
Make struct member access to work with = and ?:
1 parent 982041f commit 90d1f7f

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

codegen.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,13 @@ static void gen_addr(Node *node) {
167167
return;
168168
}
169169
break;
170+
case ND_ASSIGN:
171+
case ND_COND:
172+
if (node->ty->kind == TY_STRUCT || node->ty->kind == TY_UNION) {
173+
gen_expr(node);
174+
return;
175+
}
176+
break;
170177
case ND_VLA_PTR:
171178
println(" lea %d(%%rbp), %%rax", node->var->offset);
172179
return;

test/struct.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ int main() {
5757
ASSERT(1, ({ struct T { struct T *next; int x; } a; struct T b; b.x=1; a.next=&b; a.next->x; }));
5858
ASSERT(4, ({ typedef struct T T; struct T { int x; }; sizeof(T); }));
5959

60+
ASSERT(2, ({ struct {int a;} x={1}, y={2}; (x=y).a; }));
61+
ASSERT(1, ({ struct {int a;} x={1}, y={2}; (1?x:y).a; }));
62+
ASSERT(2, ({ struct {int a;} x={1}, y={2}; (0?x:y).a; }));
63+
6064
printf("OK\n");
6165
return 0;
6266
}

0 commit comments

Comments
 (0)