Browse Source

Integrate upstream chibicc changes

main
Justine Tunney 1 year ago
parent
commit
2ed7956be4
  1. 8
      third_party/chibicc/codegen.c
  2. 18
      third_party/chibicc/test/struct_test.c

8
third_party/chibicc/codegen.c vendored

@ -342,6 +342,13 @@ void gen_addr(Node *node) { @@ -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) { @@ -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);
}
}

18
third_party/chibicc/test/struct_test.c vendored

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

Loading…
Cancel
Save