summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Sotoudeh <matthew@masot.net>2023-07-26 16:01:53 -0700
committerMatthew Sotoudeh <matthew@masot.net>2023-07-26 16:01:53 -0700
commitc84bbdc2a296f4b818fa8ec05a6dbe2dd46fc4f1 (patch)
tree587c2597c151b285a18dd851ff910ecf10ecca7a
parent43a16ad9c3b4dd9466f1fa0ef69eee0562da99f1 (diff)
fix for postfix compound literals
-rw-r--r--parse.c20
-rw-r--r--tests/cast_index.c3
2 files changed, 14 insertions, 9 deletions
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);
diff --git a/tests/cast_index.c b/tests/cast_index.c
new file mode 100644
index 0000000..036770a
--- /dev/null
+++ b/tests/cast_index.c
@@ -0,0 +1,3 @@
+int xyz() {
+ return (int []){ 20, 21 }[1];
+}
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback