diff options
-rw-r--r-- | expr.c | 6 | ||||
-rw-r--r-- | tests/subtract-pointer.qbe | 9 |
2 files changed, 7 insertions, 8 deletions
@@ -327,9 +327,9 @@ mkbinaryexpr(struct location *loc, enum tokenkind op, struct expression *l, stru t = l->type; r = mkbinaryexpr(loc, TMUL, exprconvert(r, &typeulong), mkconstexpr(&typeulong, t->base->size)); } else if (l->type->kind == TYPEPOINTER && r->type->kind == TYPEPOINTER && typecompatible(typeunqual(l->type->base, NULL), typeunqual(r->type->base, NULL))) { - l = mkbinaryexpr(loc, TDIV, exprconvert(l, &typeulong), mkconstexpr(&typeulong, l->type->base->size)); - r = mkbinaryexpr(loc, TDIV, exprconvert(r, &typeulong), mkconstexpr(&typeulong, r->type->base->size)); - t = &typelong; + /* XXX: when is the appropriate place to convert to signed integer */ + e = mkbinaryexpr(loc, TSUB, exprconvert(l, &typelong), exprconvert(r, &typelong)); + return mkbinaryexpr(loc, TDIV, e, mkconstexpr(&typelong, l->type->base->size)); } else { error(loc, "invalid operands to '-' operator"); } diff --git a/tests/subtract-pointer.qbe b/tests/subtract-pointer.qbe index 9e49d9c..0e7e9a3 100644 --- a/tests/subtract-pointer.qbe +++ b/tests/subtract-pointer.qbe @@ -8,10 +8,9 @@ function $f(l %.1, l %.3) { @body.2 %.5 =l loadl %.2 %.6 =l copy %.5 - %.7 =l udiv %.6, 4 - %.8 =l loadl %.4 - %.9 =l copy %.8 - %.10 =l udiv %.9, 4 - %.11 =l sub %.7, %.10 + %.7 =l loadl %.4 + %.8 =l copy %.7 + %.9 =l sub %.6, %.8 + %.10 =l div %.9, 4 ret } |