aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Forney <mforney@mforney.org>2019-02-13 12:11:13 -0800
committerMichael Forney <mforney@mforney.org>2019-02-13 12:11:13 -0800
commit13fb267e24dd0fbe011d29dc6d3b2512c66118b6 (patch)
treee6073624da17fd837c97bf43aa30f179db66d864
parente22b4bd48c85de1c5f62a4ccbf178668b02f191d (diff)
expr: Perform lvalue conversion on array and index in subscript expressions
-rw-r--r--expr.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/expr.c b/expr.c
index 683d117..70d8dbf 100644
--- a/expr.c
+++ b/expr.c
@@ -378,6 +378,8 @@ postfixexpr(struct scope *s, struct expression *r)
next();
arr = r;
idx = expr(s);
+ lvalueconvert(arr);
+ lvalueconvert(idx);
if (arr->type->kind != TYPEPOINTER) {
if (idx->type->kind != TYPEPOINTER)
error(&tok.loc, "either array or index must be pointer type");
@@ -387,7 +389,6 @@ postfixexpr(struct scope *s, struct expression *r)
}
if (arr->type->base->incomplete)
error(&tok.loc, "array is pointer to incomplete type");
- lvalueconvert(idx);
if (!(typeprop(idx->type) & PROPINT))
error(&tok.loc, "index is not an integer type");
tmp = mkbinaryexpr(&tok.loc, TADD, arr, idx);