Skip to content
Snippets Groups Projects
Commit 90d1f7f1 authored by Rui Ueyama's avatar Rui Ueyama
Browse files

Make struct member access to work with `=` and `?:`

parent 982041fb
Branches main
No related merge requests found
......@@ -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;
......
......@@ -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% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment