1
0
mirror of https://github.com/golang/go synced 2024-11-26 14:08:37 -07:00

gc: handle iface == nil in back end

R=ken
OCL=33778
CL=33781
This commit is contained in:
Russ Cox 2009-08-24 15:20:37 -07:00
parent c6fd23ce6d
commit 89f69bb3be
4 changed files with 68 additions and 2 deletions

View File

@ -791,6 +791,25 @@ bgen(Node *n, int true, Prog *to)
break;
}
if(isinter(nl->type)) {
// front end shold only leave cmp to literal nil
if((a != OEQ && a != ONE) || nr->op != OLITERAL) {
yyerror("illegal interface comparison");
break;
}
a = optoas(a, types[tptr]);
regalloc(&n1, types[tptr], N);
agen(nl, &n1);
n2 = n1;
n2.op = OINDREG;
n2.xoffset = 0;
nodconst(&tmp, types[tptr], 0);
gins(optoas(OCMP, types[tptr]), &n2, &tmp);
patch(gbranch(a, types[tptr]), to);
regfree(&n1);
break;
}
a = optoas(a, nr->type);
if(nr->ullman >= UINF) {

View File

@ -743,6 +743,7 @@ bgen(Node *n, int true, Prog *to)
nl = n->left;
if(nl == N || nl->type == T)
goto ret;
break;
}
switch(n->op) {
@ -788,6 +789,25 @@ bgen(Node *n, int true, Prog *to)
break;
}
if(isinter(nl->type)) {
// front end shold only leave cmp to literal nil
if((a != OEQ && a != ONE) || nr->op != OLITERAL) {
yyerror("illegal interface comparison");
break;
}
a = optoas(a, types[tptr]);
regalloc(&n1, types[tptr], N);
agen(nl, &n1);
n2 = n1;
n2.op = OINDREG;
n2.xoffset = 0;
nodconst(&tmp, types[tptr], 0);
gins(optoas(OCMP, types[tptr]), &n2, &tmp);
patch(gbranch(a, types[tptr]), to);
regfree(&n1);
break;
}
a = optoas(a, nr->type);
if(nr->ullman >= UINF) {

View File

@ -839,6 +839,25 @@ bgen(Node *n, int true, Prog *to)
break;
}
if(isinter(nl->type)) {
// front end shold only leave cmp to literal nil
if((a != OEQ && a != ONE) || nr->op != OLITERAL) {
yyerror("illegal interface comparison");
break;
}
a = optoas(a, types[tptr]);
regalloc(&n1, types[tptr], N);
agen(nl, &n1);
n2 = n1;
n2.op = OINDREG;
n2.xoffset = 0;
nodconst(&tmp, types[tptr], 0);
gins(optoas(OCMP, types[tptr]), &n2, &tmp);
patch(gbranch(a, types[tptr]), to);
regfree(&n1);
break;
}
if(isfloat[nr->type->etype]) {
nodreg(&tmp, nr->type, D_F0);
nodreg(&n2, nr->type, D_F0 + 1);

View File

@ -323,8 +323,16 @@ reswitch:
n->op = OADDSTR;
}
if(et == TINTER) {
n->etype = n->op;
n->op = OCMPIFACE;
if(l->op == OLITERAL && l->val.ctype == CTNIL) {
// swap for back end
n->left = r;
n->right = l;
} else if(r->op == OLITERAL && r->val.ctype == CTNIL) {
// leave alone for back end
} else {
n->etype = n->op;
n->op = OCMPIFACE;
}
}
n->type = t;
goto ret;