Integrate upstream chibicc changes

main
Justine Tunney 2020-12-09 04:13:14 -08:00
parent 9df2cef4c4
commit 2ed7956be4
2 changed files with 25 additions and 1 deletions

View File

@ -342,6 +342,13 @@ void gen_addr(Node *node) {
gen_expr(node->lhs);
gen_addr(node->rhs);
return;
case ND_ASSIGN:
case ND_COND:
if (node->ty->kind == TY_STRUCT || node->ty->kind == TY_UNION) {
gen_expr(node);
return;
}
break;
case ND_MEMBER:
gen_addr(node->lhs);
if (node->member->offset) {
@ -358,7 +365,6 @@ void gen_addr(Node *node) {
println("\tlea\t%d(%%rbp),%%rax", node->var->offset);
return;
default:
DCHECK(0);
error_tok(node->tok, "not an lvalue %d", node->kind);
}
}

View File

@ -374,6 +374,24 @@ int main() {
};
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;
}));
return 0;
}