From 2ed7956be45fd9a7bf013793070360cccea747a3 Mon Sep 17 00:00:00 2001 From: Justine Tunney Date: Wed, 9 Dec 2020 04:13:14 -0800 Subject: [PATCH] Integrate upstream chibicc changes --- third_party/chibicc/codegen.c | 8 +++++++- third_party/chibicc/test/struct_test.c | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/third_party/chibicc/codegen.c b/third_party/chibicc/codegen.c index c73be830..c6c74a05 100644 --- a/third_party/chibicc/codegen.c +++ b/third_party/chibicc/codegen.c @@ -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); } } diff --git a/third_party/chibicc/test/struct_test.c b/third_party/chibicc/test/struct_test.c index c008c01a..810996d8 100644 --- a/third_party/chibicc/test/struct_test.c +++ b/third_party/chibicc/test/struct_test.c @@ -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; }