cproc

Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.nihaljere.xyz/cproc
Log | Files | Refs | Submodules | README | LICENSE

commit f2a079fa1a94b6a99e7ce432b6df17fdb4c9b554
parent ab995bcc5c65393c7d59cebb794125db7f2a6fda
Author: Michael Forney <mforney@mforney.org>
Date:   Fri, 22 Feb 2019 11:52:29 -0800

Fix adding integer to pointer

Diffstat:
Mexpr.c | 2+-
Atests/add-int-pointer.c | 4++++
Atests/add-int-pointer.qbe | 10++++++++++
3 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/expr.c b/expr.c @@ -165,7 +165,7 @@ mkbinaryexpr(struct location *loc, enum tokenkind op, struct expression *l, stru break; } if (r->type->kind == TYPEPOINTER) - e = l, l = r, r = e; + e = l, l = r, r = e, rp = lp; if (l->type->kind != TYPEPOINTER || !(rp & PROPINT)) error(loc, "invalid operands to '+' operator"); t = l->type; diff --git a/tests/add-int-pointer.c b/tests/add-int-pointer.c @@ -0,0 +1,4 @@ +int x[2]; +void f(void) { + 1 + x; +} diff --git a/tests/add-int-pointer.qbe b/tests/add-int-pointer.qbe @@ -0,0 +1,10 @@ +export +function $f() { +@start.1 +@body.2 + %.1 =l extsw 1 + %.2 =l mul %.1, 4 + %.3 =l add $x, %.2 + ret +} +export data $x = align 4 { z 8 }