diff options
author | Michael Forney <mforney@mforney.org> | 2019-02-22 11:52:29 -0800 |
---|---|---|
committer | Michael Forney <mforney@mforney.org> | 2019-02-22 11:52:29 -0800 |
commit | f2a079fa1a94b6a99e7ce432b6df17fdb4c9b554 (patch) | |
tree | 96867d860c0be717767f6a7152f78318b75293aa | |
parent | ab995bcc5c65393c7d59cebb794125db7f2a6fda (diff) | |
download | cproc-f2a079fa1a94b6a99e7ce432b6df17fdb4c9b554.tar.xz |
Fix adding integer to pointer
-rw-r--r-- | expr.c | 2 | ||||
-rw-r--r-- | tests/add-int-pointer.c | 4 | ||||
-rw-r--r-- | tests/add-int-pointer.qbe | 10 |
3 files changed, 15 insertions, 1 deletions
@@ -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 new file mode 100644 index 0000000..be1a60f --- /dev/null +++ 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 new file mode 100644 index 0000000..22825ee --- /dev/null +++ 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 } |