Generate the right code for indexing pointer to array.
@@ -11745,15 +11745,16 @@ static op_t gen (c2m_ctx_t c2m_ctx, node_t r, MIR_label_t true_label, MIR_label_
case N_IND: {
MIR_type_t ind_t;
node_t arr = NL_HEAD (r->u.ops);
- mir_size_t size = type_size (c2m_ctx, ((struct expr *) r->attr)->type);
+ struct type *type = ((struct expr *) r->attr)->type;
+ mir_size_t size = type_size (c2m_ctx, type);
- t = get_mir_type (c2m_ctx, ((struct expr *) r->attr)->type);
+ t = get_mir_type (c2m_ctx, type);
op1 = gen (c2m_ctx, arr, NULL, NULL, TRUE, NULL);
op2 = gen (c2m_ctx, NL_EL (r->u.ops, 1), NULL, NULL, TRUE, NULL);
ind_t = get_mir_type (c2m_ctx, ((struct expr *) NL_EL (r->u.ops, 1)->attr)->type);
op2 = force_reg (c2m_ctx, op2, ind_t);
- if (((struct expr *) arr->attr)->type->arr_type != NULL) { /* it was an array */
- size = type_size (c2m_ctx, ((struct expr *) arr->attr)->type->arr_type->u.arr_type->el_type);
+ if (type->mode == TM_PTR && type->arr_type != NULL) { /* it was an array */
+ size = type_size (c2m_ctx, type->arr_type);
op1 = force_reg_or_mem (c2m_ctx, op1, MIR_T_I64);
assert (op1.mir_op.mode == MIR_OP_REG || op1.mir_op.mode == MIR_OP_MEM);
} else {
