diff options
author | Michael Forney <mforney@mforney.org> | 2021-09-29 15:03:15 -0700 |
---|---|---|
committer | Michael Forney <mforney@mforney.org> | 2021-09-29 15:04:44 -0700 |
commit | e36dc296f50cb2d60d3b27ce62217762b9655313 (patch) | |
tree | 91c5e1d3ede6ae92d2310866c2f71db28c840a2f /eval.c | |
parent | 8a08b602e30054c283adb8fc1a4077aaf99efbca (diff) |
eval: Allow subtraction in address constants
Diffstat (limited to 'eval.c')
-rw-r--r-- | eval.c | 14 |
1 files changed, 7 insertions, 7 deletions
@@ -157,19 +157,19 @@ eval(struct expr *expr, enum evalkind kind) case TADD: if (r->kind == EXPRBINARY) c = l, l = r, r = c; + /* fallthrough */ + case TSUB: if (r->kind != EXPRCONST) break; if (l->kind == EXPRCONST) { binary(expr, expr->op, l, r); - } else if (l->kind == EXPRBINARY && l->type->kind == TYPEPOINTER && l->binary.r->kind == EXPRCONST) { - if (l->op == TADD || l->op == TSUB) { - /* (P ± C1) + C2 -> P + (C2 ± C1) */ - expr->binary.l = l->binary.l; - binary(expr->binary.r, l->op, r, l->binary.r); - } + } else if (l->kind == EXPRBINARY && l->type->kind == TYPEPOINTER && l->op == TADD && l->binary.r->kind == EXPRCONST) { + /* (P + C1) ± C2 -> P + (C1 ± C2) */ + binary(expr->binary.r, expr->op, l->binary.r, r); + expr->op = TADD; + expr->binary.l = l->binary.l; } break; - /* TODO: TSUB pointer handling */ case TLOR: if (l->kind != EXPRCONST) break; |