Skip to content

Commit

Permalink
Make struct member access to work with = and ?:
Browse files Browse the repository at this point in the history
  • Loading branch information
rui314 committed Dec 7, 2020
1 parent 982041f commit 90d1f7f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
7 changes: 7 additions & 0 deletions codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,13 @@ static void gen_addr(Node *node) {
return;
}
break;
case ND_ASSIGN:
case ND_COND:
if (node->ty->kind == TY_STRUCT || node->ty->kind == TY_UNION) {
gen_expr(node);
return;
}
break;
case ND_VLA_PTR:
println(" lea %d(%%rbp), %%rax", node->var->offset);
return;
Expand Down
4 changes: 4 additions & 0 deletions test/struct.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ int main() {
ASSERT(1, ({ struct T { struct T *next; int x; } a; struct T b; b.x=1; a.next=&b; a.next->x; }));
ASSERT(4, ({ typedef struct T T; struct T { int x; }; sizeof(T); }));

ASSERT(2, ({ struct {int a;} x={1}, y={2}; (x=y).a; }));
ASSERT(1, ({ struct {int a;} x={1}, y={2}; (1?x:y).a; }));
ASSERT(2, ({ struct {int a;} x={1}, y={2}; (0?x:y).a; }));

printf("OK\n");
return 0;
}

0 comments on commit 90d1f7f

Please sign in to comment.