Clean up array expression processing

And make sure constants are folded since fold_constants is no longer
recursive.
This commit is contained in:
Bill Currie 2019-06-09 22:25:55 +09:00
parent f70801fa52
commit 227ac46ffe

View file

@ -2106,6 +2106,8 @@ array_expr (expr_t *array, expr_t *index)
type_t *array_type = get_type (array); type_t *array_type = get_type (array);
type_t *index_type = get_type (index); type_t *index_type = get_type (index);
expr_t *scale; expr_t *scale;
expr_t *offset;
expr_t *base;
expr_t *e; expr_t *e;
int ind = 0; int ind = 0;
@ -2128,12 +2130,10 @@ array_expr (expr_t *array, expr_t *index)
|| ind - array_type->t.array.base >= array_type->t.array.size)) || ind - array_type->t.array.base >= array_type->t.array.size))
return error (index, "array index out of bounds"); return error (index, "array index out of bounds");
scale = new_integer_expr (type_size (array_type->t.array.type)); scale = new_integer_expr (type_size (array_type->t.array.type));
index = binary_expr ('*', index, scale); index = fold_constants (binary_expr ('*', index, scale));
index = binary_expr ('-', index, base = new_integer_expr (array_type->t.array.base);
binary_expr ('*', offset = fold_constants (binary_expr ('*', base, scale));
new_integer_expr (array_type->t.array.base), index = fold_constants (binary_expr ('-', index, offset));
scale));
index = fold_constants (index);
if (is_short_val (index)) if (is_short_val (index))
ind = expr_short (index); ind = expr_short (index);
if (is_integer_val (index)) if (is_integer_val (index))