Commit 78c8dec9 authored by Ken Thompson's avatar Ken Thompson

bug miscalculating ullman

in CALLMETH/DOTMETH

SVN=124321
parent d4c2da40
...@@ -19,19 +19,22 @@ cgen(Node *n, Node *res) ...@@ -19,19 +19,22 @@ cgen(Node *n, Node *res)
} }
if(n == N || n->type == T) if(n == N || n->type == T)
return; return;
lno = dynlineno;
if(n->op != ONAME)
dynlineno = n->lineno; // for diagnostics
if(res == N || res->type == T) if(res == N || res->type == T)
fatal("cgen: res nil"); fatal("cgen: res nil");
if(n->ullman >= UINF) { if(n->ullman >= UINF) {
if(n->op == OINDREG) if(n->op == OINDREG)
fatal("cgen: this is going to misscompile"); fatal("cgen: this is going to misscompile");
if(res->ullman >= UINF) if(res->ullman >= UINF) {
fatal("cgen: fun both sides"); dump("fncalls", n);
fatal("cgen: node and result functions");
}
} }
lno = dynlineno;
if(n->op != ONAME)
dynlineno = n->lineno; // for diagnostics
if(isfat(n->type)) { if(isfat(n->type)) {
sgen(n, res, n->type->width); sgen(n, res, n->type->width);
...@@ -62,6 +65,7 @@ cgen(Node *n, Node *res) ...@@ -62,6 +65,7 @@ cgen(Node *n, Node *res)
nr = n->right; nr = n->right;
if(nl != N && nl->ullman >= UINF) if(nl != N && nl->ullman >= UINF)
if(nr != N && nr->ullman >= UINF) { if(nr != N && nr->ullman >= UINF) {
dump("fncalls", n);
fatal("cgen: both sides functions"); fatal("cgen: both sides functions");
goto ret; goto ret;
} }
......
...@@ -658,7 +658,7 @@ cgen_callret(Node *n, Node *res) ...@@ -658,7 +658,7 @@ cgen_callret(Node *n, Node *res)
fp = structfirst(&flist, getoutarg(t)); fp = structfirst(&flist, getoutarg(t));
if(fp == T) if(fp == T)
fatal("cgen_aret: nil"); fatal("cgen_callret: nil");
memset(&nod, 0, sizeof(nod)); memset(&nod, 0, sizeof(nod));
nod.op = OINDREG; nod.op = OINDREG;
...@@ -677,16 +677,14 @@ cgen_aret(Node *n, Node *res) ...@@ -677,16 +677,14 @@ cgen_aret(Node *n, Node *res)
Type *fp, *t; Type *fp, *t;
Iter flist; Iter flist;
fatal("cgen_aret");
t = n->left->type; t = n->left->type;
if(t->etype == TPTR32 || t->etype == TPTR64) if(isptr[t->etype])
t = t->type; t = t->type;
fp = structfirst(&flist, getoutarg(t)); fp = structfirst(&flist, getoutarg(t));
if(fp == T) if(fp == T)
fatal("cgen_aret: nil"); fatal("cgen_aret: nil");
/* gins LEA */
memset(&nod1, 0, sizeof(nod1)); memset(&nod1, 0, sizeof(nod1));
nod1.op = OINDREG; nod1.op = OINDREG;
nod1.val.vval = D_SP; nod1.val.vval = D_SP;
......
...@@ -1516,6 +1516,8 @@ ullmancalc(Node *n) ...@@ -1516,6 +1516,8 @@ ullmancalc(Node *n)
case OI2S: case OI2S:
case OI2I: case OI2I:
case OCALL: case OCALL:
case OCALLMETH:
case OCALLINTER:
ul = UINF; ul = UINF;
goto out; goto out;
} }
......
...@@ -76,7 +76,6 @@ loop: ...@@ -76,7 +76,6 @@ loop:
if(top != Erv) if(top != Erv)
goto nottop; goto nottop;
n->addable = 1; n->addable = 1;
ullmancalc(n);
goto ret; goto ret;
case ONONAME: case ONONAME:
...@@ -94,7 +93,6 @@ loop: ...@@ -94,7 +93,6 @@ loop:
if(top == Etop) if(top == Etop)
goto nottop; goto nottop;
n->addable = 1; n->addable = 1;
ullmancalc(n);
if(n->type == T) { if(n->type == T) {
s = n->sym; s = n->sym;
if(s->undef == 0) { if(s->undef == 0) {
...@@ -163,14 +161,12 @@ loop: ...@@ -163,14 +161,12 @@ loop:
if(top == Elv) if(top == Elv)
goto nottop; goto nottop;
n->ullman = UINF;
if(n->type != T) if(n->type != T)
goto ret; goto ret;
walktype(n->left, Erv); walktype(n->left, Erv);
if(n->left == N) if(n->left == N)
goto ret; goto ret;
t = n->left->type; t = n->left->type;
if(t == T) if(t == T)
goto ret; goto ret;
...@@ -210,14 +206,12 @@ loop: ...@@ -210,14 +206,12 @@ loop:
break; break;
case OCALLMETH: case OCALLMETH:
// add this-pointer to the arg list
// this is bad - if not a simple
// should make a temp copy rather
// than recalculate it.
l = ascompatte(n->op, getinarg(t), &n->right, 0); l = ascompatte(n->op, getinarg(t), &n->right, 0);
r = ascompatte(n->op, getthis(t), &n->left->left, 0); r = ascompatte(n->op, getthis(t), &n->left->left, 0);
if(l != N) if(l != N)
r = nod(OLIST, r, l); r = nod(OLIST, r, l);
n->left->left = N;
ullmancalc(n->left);
n->right = reorder1(r); n->right = reorder1(r);
break; break;
} }
...@@ -442,7 +436,6 @@ loop: ...@@ -442,7 +436,6 @@ loop:
if(n->left == N) if(n->left == N)
goto ret; goto ret;
evconst(n); evconst(n);
ullmancalc(n);
if(n->op == OLITERAL) if(n->op == OLITERAL)
goto ret; goto ret;
break; break;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment