mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-10 15:22:04 +00:00
[qfcc] Support pointer arithmetic on arrays
That is, `array + offset`. This actually works around the bug highlighted by arraylife.r (because the array is explicitly used), but is not a proper solution, so that test still fails of course. However, with this, it's no longer necessary to use `&array[index]` instead of `array + index`.
This commit is contained in:
parent
8e1883a306
commit
4435db0329
2 changed files with 13 additions and 0 deletions
|
@ -1119,6 +1119,14 @@ binary_expr (int op, expr_t *e1, expr_t *e2)
|
||||||
t2 = &type_float;
|
t2 = &type_float;
|
||||||
e2 = cast_expr (t2, e2);
|
e2 = cast_expr (t2, e2);
|
||||||
}
|
}
|
||||||
|
if (is_array (t1) && (is_ptr (t2) || is_integral (t2))) {
|
||||||
|
t1 = pointer_type (t1->t.array.type);
|
||||||
|
e1 = cast_expr (t1, e1);
|
||||||
|
}
|
||||||
|
if (is_array (t2) && (is_ptr (t1) || is_integral (t1))) {
|
||||||
|
t2 = pointer_type (t2->t.array.type);
|
||||||
|
e2 = cast_expr (t2, e2);
|
||||||
|
}
|
||||||
|
|
||||||
et1 = low_level_type (t1);
|
et1 = low_level_type (t1);
|
||||||
et2 = low_level_type (t2);
|
et2 = low_level_type (t2);
|
||||||
|
|
|
@ -677,6 +677,11 @@ expr_address (sblock_t *sblock, expr_t *e, operand_t **op)
|
||||||
lvalue->e.alias.expr,
|
lvalue->e.alias.expr,
|
||||||
expr_int (offset));
|
expr_int (offset));
|
||||||
offset = 0;
|
offset = 0;
|
||||||
|
} else if (offset && is_constant (offset)) {
|
||||||
|
int o = expr_int (offset);
|
||||||
|
if (o < 32768 && o >= -32768) {
|
||||||
|
offset = expr_file_line (new_short_expr (o), offset);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
s = new_statement (st_address, "lea", e);
|
s = new_statement (st_address, "lea", e);
|
||||||
|
|
Loading…
Reference in a new issue