mirror of https://github.com/rui314/chibicc
Make struct member access to work with `=` and `?:`
This commit is contained in:
parent
982041fb1c
commit
90d1f7f199
|
@ -167,6 +167,13 @@ static void gen_addr(Node *node) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
break;
|
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:
|
case ND_VLA_PTR:
|
||||||
println(" lea %d(%%rbp), %%rax", node->var->offset);
|
println(" lea %d(%%rbp), %%rax", node->var->offset);
|
||||||
return;
|
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(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(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");
|
printf("OK\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue