ref: 80126fceaea7d2fc98094d1e280757f686bead22
parent: 4b51d0d03ae39f5a48f45d0d408a42917f6f099f
author: Ori Bernstein <[email protected]>
date: Sun Jul 22 00:38:47 EDT 2012
Fix taking addresses of exprssions. We need lvals, not rvals.
--- a/8/isel.c
+++ b/8/isel.c
@@ -232,14 +232,17 @@
/* if we have a cond, we're knocking off the redundant test,
* and want to eval the children */
if (cond) {
- a = selexpr(s, args[0]->expr.args[1]);
- b = selexpr(s, args[0]->expr.args[0]);
- b = inr(s, b);
+ a = selexpr(s, args[0]->expr.args[0]);
+ if (args[0]->expr.nargs == 2)
+ b = selexpr(s, args[0]->expr.args[1]);
+ else
+ b = a;
+ a = inr(s, a);
} else {
cond = Itest;
jmp = Ijnz;
- a = inr(s, selexpr(s, args[0])); /* cond */
- b = a;
+ b = inr(s, selexpr(s, args[0])); /* cond */
+ a = b;
}
/* the jump targets will always be evaluated the same way */
@@ -246,7 +249,7 @@
l1 = loclbl(args[1]); /* if true */
l2 = loclbl(args[2]); /* if false */
- g(s, cond, a, b, NULL);
+ g(s, cond, b, a, NULL);
g(s, jmp, l1, NULL);
g(s, Ijmp, l2, NULL);
}
@@ -537,7 +540,6 @@
r = locreg(mode(n));
g(s, Imov, b, r, NULL);
break;
-
case Ocall:
r = gencall(s, n);
break;
--- a/8/simp.c
+++ b/8/simp.c
@@ -666,16 +666,20 @@
{
Node **args;
Node *r;
+ Type *t;
r = NULL;
args = n->expr.args;
switch (exprtype(n)->type) {
case Typtr:
- switch (exprtype(args[0])->type) {
+ t = tybase(exprtype(args[0]));
+ switch (t->type) {
case Tyslice:
r = slicebase(s, args[0], zero);
break;
- case Tyint:
+ case Tyint8: case Tyint16: case Tyint32: case Tyint64:
+ case Tyuint8: case Tyuint16: case Tyuint32: case Tyuint64:
+ case Tyint: case Tyuint: case Tylong: case Tyulong:
args[0]->expr.type = n->expr.type;
r = args[0];
break;
@@ -984,6 +988,13 @@
} else {
r = visit(s, n);
}
+ break;
+ case Oaddr:
+ t = lval(s, args[0]);
+ if (exprop(t) == Ovar) /* Ovar is the only one that doesn't return the address directly */
+ r = addr(t, exprtype(t));
+ else
+ r = t;
break;
default:
r = visit(s, n);
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -329,7 +329,7 @@
a->cstrs = bsdup(b->cstrs);
} else {
if (!cstrcheck(a, b)) {
- dump(file, stdout);
+ /* FIXME: say WHICH constraints we're missing */
fatal(ctx->line, "%s missing constraints for %s near %s", tystr(b), tystr(a), ctxstr(st, ctx));
}
}
--- a/test/tests
+++ b/test/tests
@@ -24,6 +24,7 @@
B structasn E 42
B structret E 42
B array E 7
+B arrayaddr E 42
B global-arrayvar E 7
B arraylen E 12
B slice E 7