diff options
author | Matthew Sotoudeh <matthew@masot.net> | 2023-07-26 16:01:53 -0700 |
---|---|---|
committer | Matthew Sotoudeh <matthew@masot.net> | 2023-07-26 16:01:53 -0700 |
commit | c84bbdc2a296f4b818fa8ec05a6dbe2dd46fc4f1 (patch) | |
tree | 587c2597c151b285a18dd851ff910ecf10ecca7a /parse.c | |
parent | 43a16ad9c3b4dd9466f1fa0ef69eee0562da99f1 (diff) |
fix for postfix compound literals
Diffstat (limited to 'parse.c')
-rw-r--r-- | parse.c | 20 |
1 files changed, 11 insertions, 9 deletions
@@ -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); |