1
0
mirror of https://github.com/golang/go synced 2024-11-19 02:24:41 -07:00

bugs 29, 61, 62, 74

fixedbugs 49 now (correctly) fails
bugs 32, 41, 68, 77 shouldnt be bugs

R=r
OCL=14842
CL=14842
This commit is contained in:
Ken Thompson 2008-09-04 17:15:15 -07:00
parent cae0342230
commit 193eac7917
5 changed files with 60 additions and 58 deletions

View File

@ -172,9 +172,17 @@ cgen(Node *n, Node *res)
if(isptrto(nl->type, TSTRING)) { if(isptrto(nl->type, TSTRING)) {
regalloc(&n1, types[tptr], res); regalloc(&n1, types[tptr], res);
cgen(nl, &n1); cgen(nl, &n1);
nodconst(&n2, types[tptr], 0);
gins(optoas(OCMP, types[tptr]), &n1, &n2);
p1 = gbranch(optoas(OEQ, types[tptr]), T);
n1.op = OINDREG; n1.op = OINDREG;
n1.type = types[TINT32]; n1.type = types[TINT32];
gmove(&n1, res); gmove(&n1, res);
patch(p1, pc);
regfree(&n1); regfree(&n1);
break; break;
} }

View File

@ -947,27 +947,9 @@ cgen_as(Node *nl, Node *nr, int op)
case TPTR32: case TPTR32:
case TPTR64: case TPTR64:
if(isptrto(tl, TSTRING)) {
nr->val.u.sval = mal(8);
nr->val.ctype = CTSTR;
break;
}
nr->val.ctype = CTNIL; nr->val.ctype = CTNIL;
break; break;
// case TINTER:
// nodreg(&n1, types[tptr], D_DI);
// agen(nl, &n1);
// n1.op = OINDREG;
//
// nodreg(&nc, types[tptr], D_AX);
// gconreg(AMOVQ, 0, D_AX);
//
// gins(AMOVQ, &nc, &n1);
// n1.xoffset += widthptr;
// gins(AMOVQ, &nc, &n1);
// goto ret;
} }
nr->op = OLITERAL; nr->op = OLITERAL;
nr->type = tl; nr->type = tl;

View File

@ -43,10 +43,8 @@ convlit(Node *n, Type *t)
case Wlitnil: case Wlitnil:
if(!isptr[et] && et != TINTER) if(!isptr[et] && et != TINTER)
goto bad1; goto bad1;
if(isptrto(t, TSTRING)) { if(isptrto(t, TSTRING))
n->val.u.sval = mal(8); goto bad1;
n->val.ctype = CTSTR;
}
break; break;
case Wlitstr: case Wlitstr:

View File

@ -956,7 +956,10 @@ Atype:
{ {
$$ = dostruct(N, TINTER); $$ = dostruct(N, TINTER);
} }
| Afntypeh | '*'Afntypeh
{
$$ = ptrto($2);
}
| '*' Atype | '*' Atype
{ {
dowidth($2); dowidth($2);
@ -980,7 +983,10 @@ Btype:
$$->down = $3; $$->down = $3;
$$->type = $5; $$->type = $5;
} }
| Bfntypeh | '*' Bfntypeh
{
$$ = ptrto($2);
}
| '*' Btype | '*' Btype
{ {
dowidth($2); dowidth($2);

View File

@ -82,6 +82,13 @@ loop:
} }
} }
void
indir(Node *nl, Node *nr)
{
if(nr != N)
*nl = *nr;
}
void void
walktype(Node *n, int top) walktype(Node *n, int top)
{ {
@ -126,14 +133,14 @@ loop:
if(top != Etop) if(top != Etop)
goto nottop; goto nottop;
walktype(n->left, Erv); walktype(n->left, Erv);
*n = *prcompat(n->left); indir(n, prcompat(n->left));
goto ret; goto ret;
case OPANIC: case OPANIC:
if(top != Etop) if(top != Etop)
goto nottop; goto nottop;
walktype(n->left, Erv); walktype(n->left, Erv);
*n = *list(prcompat(n->left), nodpanic(n->lineno)); indir(n, list(prcompat(n->left), nodpanic(n->lineno)));
goto ret; goto ret;
case OLITERAL: case OLITERAL:
@ -313,7 +320,7 @@ loop:
walktype(r, Erv); walktype(r, Erv);
l = ascompatee(n->op, &n->left, &n->right); l = ascompatee(n->op, &n->left, &n->right);
if(l != N) if(l != N)
*n = *reorder3(l); indir(n, reorder3(l));
goto ret; goto ret;
} }
@ -326,9 +333,8 @@ loop:
// a,b,... = fn() // a,b,... = fn()
walktype(r, Erv); walktype(r, Erv);
l = ascompatet(n->op, &n->left, &r->type, 0); l = ascompatet(n->op, &n->left, &r->type, 0);
if(l != N) { if(l != N)
*n = *list(r, reorder2(l)); indir(n, list(r, reorder2(l)));
}
goto ret; goto ret;
} }
break; break;
@ -342,7 +348,7 @@ loop:
l = mapop(n, top); l = mapop(n, top);
if(l == N) if(l == N)
break; break;
*n = *l; indir(n, l);
goto ret; goto ret;
} }
break; break;
@ -356,7 +362,7 @@ loop:
l = chanop(n, top); l = chanop(n, top);
if(l == N) if(l == N)
break; break;
*n = *l; indir(n, l);
goto ret; goto ret;
} }
break; break;
@ -372,7 +378,7 @@ loop:
l = mapop(n, top); l = mapop(n, top);
if(l == N) if(l == N)
break; break;
*n = *l; indir(n, l);
goto ret; goto ret;
} }
break; break;
@ -438,7 +444,7 @@ loop:
// nil conversion // nil conversion
if(eqtype(t, l->type, 0)) { if(eqtype(t, l->type, 0)) {
if(l->op != ONAME) if(l->op != ONAME)
*n = *l; indir(n, l);
goto ret; goto ret;
} }
@ -454,12 +460,12 @@ loop:
if(l->type != T) if(l->type != T)
if(isptrto(t, TSTRING)) { if(isptrto(t, TSTRING)) {
if(isint[l->type->etype]) { if(isint[l->type->etype]) {
*n = *stringop(n, top); indir(n, stringop(n, top));
goto ret; goto ret;
} }
if(bytearraysz(l->type) != -2) { if(bytearraysz(l->type) != -2) {
n->op = OARRAY; n->op = OARRAY;
*n = *stringop(n, top); indir(n, stringop(n, top));
goto ret; goto ret;
} }
} }
@ -471,28 +477,27 @@ loop:
// interface and structure // interface and structure
r = isandss(n->type, l); r = isandss(n->type, l);
if(r != N) { if(r != N) {
*n = *r; indir(n, r);
goto ret; goto ret;
} }
// structure literal // structure literal
if(t->etype == TSTRUCT) { if(t->etype == TSTRUCT) {
r = structlit(n); indir(n, structlit(n));
*n = *r;
goto ret; goto ret;
} }
// structure literal // structure literal
if(t->etype == TARRAY) { if(t->etype == TARRAY) {
r = arraylit(n); r = arraylit(n);
*n = *r; indir(n, r);
goto ret; goto ret;
} }
// map literal // map literal
if(t->etype == TMAP) { if(t->etype == TMAP) {
r = maplit(n); r = maplit(n);
*n = *r; indir(n, r);
goto ret; goto ret;
} }
@ -533,7 +538,7 @@ loop:
} }
if(!isptrto(l->left->type, TMAP)) if(!isptrto(l->left->type, TMAP))
goto com; goto com;
*n = *mapop(n, top); indir(n, mapop(n, top));
goto ret; goto ret;
case OLSH: case OLSH:
@ -601,7 +606,7 @@ loop:
case OADD: case OADD:
case OASOP: case OASOP:
if(isptrto(n->left->type, TSTRING)) { if(isptrto(n->left->type, TSTRING)) {
*n = *stringop(n, top); indir(n, stringop(n, top));
goto ret; goto ret;
} }
} }
@ -695,7 +700,7 @@ loop:
} }
if(!isint[n->right->type->etype]) if(!isint[n->right->type->etype])
goto badt; goto badt;
*n = *stringop(n, top); indir(n, stringop(n, top));
goto ret; goto ret;
} }
@ -723,7 +728,7 @@ loop:
n->op = OINDEX; n->op = OINDEX;
n->type = t->type; n->type = t->type;
if(top == Erv) if(top == Erv)
*n = *mapop(n, top); indir(n, mapop(n, top));
break; break;
case TARRAY: case TARRAY:
@ -746,20 +751,20 @@ loop:
goto nottop; goto nottop;
walktype(n->left, Erv); // chan walktype(n->left, Erv); // chan
walktype(n->right, Erv); // e walktype(n->right, Erv); // e
*n = *chanop(n, top); indir(n, chanop(n, top));
goto ret; goto ret;
case ORECV: case ORECV:
if(top == Elv) if(top == Elv)
goto nottop; goto nottop;
if(n->right == N) { if(n->right == N) {
walktype(n->left, Erv); // chan walktype(n->left, Erv); // chan
*n = *chanop(n, top); // returns e blocking indir(n, chanop(n, top)); // returns e blocking
goto ret; goto ret;
} }
walktype(n->left, Elv); // e walktype(n->left, Elv); // e
walktype(n->right, Erv); // chan walktype(n->right, Erv); // chan
*n = *chanop(n, top); // returns bool non-blocking indir(n, chanop(n, top)); // returns bool non-blocking
goto ret; goto ret;
case OSLICE: case OSLICE:
@ -770,15 +775,18 @@ loop:
walktype(n->right, Erv); walktype(n->right, Erv);
if(n->left == N || n->right == N) if(n->left == N || n->right == N)
goto ret; goto ret;
convlit(n->left, types[TSTRING]);
t = n->left->type; t = n->left->type;
if(t == T)
goto ret;
if(isptr[t->etype]) if(isptr[t->etype])
t = t->type; t = t->type;
if(t->etype == TSTRING) { if(t->etype == TSTRING) {
*n = *stringop(n, top); indir(n, stringop(n, top));
goto ret; goto ret;
} }
if(t->etype == TARRAY) { if(t->etype == TARRAY) {
*n = *arrayop(n, top); indir(n, arrayop(n, top));
goto ret; goto ret;
} }
badtype(OSLICE, n->left->type, T); badtype(OSLICE, n->left->type, T);
@ -822,7 +830,7 @@ loop:
case ONEW: case ONEW:
if(top != Erv) if(top != Erv)
goto nottop; goto nottop;
*n = *newcompat(n); indir(n, newcompat(n));
goto ret; goto ret;
} }
@ -889,7 +897,7 @@ loop:
mpmovecflt(l->val.u.fval, 0.0); mpmovecflt(l->val.u.fval, 0.0);
l = nod(OSUB, l, n->left); l = nod(OSUB, l, n->left);
*n = *l; indir(n, l);
walktype(n, Erv); walktype(n, Erv);
goto ret; goto ret;
@ -2027,7 +2035,7 @@ mapop(Node *n, int top)
n->left->right = a; // m[tmpi] n->left->right = a; // m[tmpi]
a = nod(OXXX, N, N); a = nod(OXXX, N, N);
*a = *n->left; // copy of map[tmpi] indir(a, n->left); // copy of map[tmpi]
a = nod(n->etype, a, n->right); // m[tmpi] op right a = nod(n->etype, a, n->right); // m[tmpi] op right
a = nod(OAS, n->left, a); // map[tmpi] = map[tmpi] op right a = nod(OAS, n->left, a); // map[tmpi] = map[tmpi] op right
r = nod(OLIST, r, a); r = nod(OLIST, r, a);
@ -2441,19 +2449,19 @@ convas(Node *n)
if(n->left->op == OINDEX) if(n->left->op == OINDEX)
if(isptrto(n->left->left->type, TMAP)) { if(isptrto(n->left->left->type, TMAP)) {
*n = *mapop(n, Elv); indir(n, mapop(n, Elv));
goto out; goto out;
} }
if(n->left->op == OINDEXPTR) if(n->left->op == OINDEXPTR)
if(n->left->left->type->etype == TMAP) { if(n->left->left->type->etype == TMAP) {
*n = *mapop(n, Elv); indir(n, mapop(n, Elv));
goto out; goto out;
} }
if(n->left->op == OSEND) if(n->left->op == OSEND)
if(n->left->type != T) { if(n->left->type != T) {
*n = *chanop(n, Elv); indir(n, chanop(n, Elv));
goto out; goto out;
} }
@ -2470,7 +2478,7 @@ convas(Node *n)
if(isptrdarray(lt) && isptrarray(rt)) { if(isptrdarray(lt) && isptrarray(rt)) {
if(!eqtype(lt->type->type, rt->type->type, 0)) if(!eqtype(lt->type->type, rt->type->type, 0))
goto bad; goto bad;
*n = *arrayop(n, Etop); indir(n, arrayop(n, Etop));
goto out; goto out;
} }