From c84bbdc2a296f4b818fa8ec05a6dbe2dd46fc4f1 Mon Sep 17 00:00:00 2001 From: Matthew Sotoudeh Date: Wed, 26 Jul 2023 16:01:53 -0700 Subject: fix for postfix compound literals --- parse.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'parse.c') diff --git a/parse.c b/parse.c index 0963095..fe17515 100644 --- a/parse.c +++ b/parse.c @@ -2812,7 +2812,9 @@ static Node *new_inc_dec(Node *node, Token *tok, int addend) { // | "->" ident // | "++" // | "--" +// fixed per: https://github.com/rui314/chibicc/issues/84 static Node *postfix(Token **rest, Token *tok) { + Node *node = 0; if (equal(tok, "(") && is_typename(tok->next)) { // Compound literal Token *start = tok; @@ -2821,18 +2823,18 @@ static Node *postfix(Token **rest, Token *tok) { if (scope->next == NULL) { Obj *var = new_anon_gvar(ty); - gvar_initializer(rest, tok, var); - return new_var_node(var, start); + gvar_initializer(&tok, tok, var); + node = new_var_node(var, start); + } else { + Obj *var = new_lvar("", ty); + Node *lhs = lvar_initializer(&tok, tok, var); + Node *rhs = new_var_node(var, tok); + node = new_binary(ND_COMMA, lhs, rhs, start); } - - Obj *var = new_lvar("", ty); - Node *lhs = lvar_initializer(rest, tok, var); - Node *rhs = new_var_node(var, tok); - return new_binary(ND_COMMA, lhs, rhs, start); + } else { + node = primary(&tok, tok); } - Node *node = primary(&tok, tok); - for (;;) { if (equal(tok, "(")) { node = funcall(&tok, tok->next, node); -- cgit v1.2.3