Commit 0aef57e3 authored by Russ Cox's avatar Russ Cox

fix a 6g crash after type errors.

do not bother warning about marks left
on stack after syntax errors.

leave OCONV nodes in tree to avoid type errors
arising from multiple walks.

R=ken
OCL=30639
CL=30662
parent 57665533
......@@ -28,6 +28,9 @@ cgen(Node *n, Node *res)
if(res == N || res->type == T)
fatal("cgen: res nil");
while(n->op == OCONVNOP)
n = n->left;
// static initializations
if(initflag && gen_as_init(n, res))
goto ret;
......@@ -197,10 +200,6 @@ cgen(Node *n, Node *res)
goto abop;
case OCONV:
if(eqtype(n->type, nl->type)) {
cgen(nl, res);
break;
}
regalloc(&n1, nl->type, res);
cgen(nl, &n1);
gmove(&n1, res);
......@@ -373,7 +372,10 @@ agen(Node *n, Node *res)
// if(!isptr[res->type->etype])
// fatal("agen: not tptr: %T", res->type);
//
// while(n->op == OCONVNOP)
// n = n->left;
//
// if(n->addable) {
// regalloc(&n1, types[tptr], res);
// gins(ALEAQ, n, &n1);
......@@ -390,12 +392,6 @@ agen(Node *n, Node *res)
// fatal("agen: unknown op %N", n);
// break;
// case OCONV:
// if(!cvttype(n->type, nl->type))
// fatal("agen: non-trivial OCONV");
// agen(nl, res);
// return;
// case OCALLMETH:
// cgen_callmeth(n, 0);
// cgen_aret(n, res);
......
......@@ -28,6 +28,9 @@ cgen(Node *n, Node *res)
if(res == N || res->type == T)
fatal("cgen: res nil");
while(n->op == OCONVNOP)
n = n->left;
// static initializations
if(initflag && gen_as_init(n, res))
goto ret;
......@@ -196,10 +199,6 @@ cgen(Node *n, Node *res)
goto abop;
case OCONV:
if(eqtype(n->type, nl->type)) {
cgen(nl, res);
break;
}
regalloc(&n1, nl->type, res);
regalloc(&n2, n->type, &n1);
cgen(nl, &n1);
......@@ -378,6 +377,9 @@ agen(Node *n, Node *res)
if(!isptr[res->type->etype])
fatal("agen: not tptr: %T", res->type);
while(n->op == OCONVNOP)
n = n->left;
if(n->addable) {
regalloc(&n1, types[tptr], res);
gins(ALEAQ, n, &n1);
......@@ -394,12 +396,6 @@ agen(Node *n, Node *res)
fatal("agen: unknown op %N", n);
break;
case OCONV:
if(!cvttype(n->type, nl->type))
fatal("agen: non-trivial OCONV");
agen(nl, res);
return;
case OCALLMETH:
cgen_callmeth(n, 0);
cgen_aret(n, res);
......
......@@ -61,6 +61,9 @@ cgen(Node *n, Node *res)
if(res == N || res->type == T)
fatal("cgen: res nil");
while(n->op == OCONVNOP)
n = n->left;
// static initializations
if(initflag && gen_as_init(n, res))
return;
......@@ -403,6 +406,9 @@ agen(Node *n, Node *res)
if(n == N || n->type == T || res == N || res->type == T)
fatal("agen");
while(n->op == OCONVNOP)
n = n->left;
// addressable var is easy
if(n->addable) {
if(n->op == OREGISTER)
......@@ -422,12 +428,6 @@ agen(Node *n, Node *res)
default:
fatal("agen %O", n->op);
case OCONV:
if(!cvttype(n->type, nl->type))
fatal("agen: non-trivial OCONV");
agen(nl, res);
break;
case OCALLMETH:
cgen_callmeth(n, 0);
cgen_aret(n, res);
......
......@@ -327,7 +327,7 @@ enum
OREGISTER, OINDREG,
OKEY, OPARAM,
OCOMPOS, OCOMPSLICE, OCOMPMAP,
OCONV,
OCONV, OCONVNOP,
ODOTTYPE, OTYPESW,
OBAD,
......@@ -530,6 +530,7 @@ EXTERN char* outfile;
EXTERN char* package;
EXTERN Biobuf* bout;
EXTERN int nerrors;
EXTERN int nsyntaxerrors;
EXTERN char namebuf[NSYMB];
EXTERN char lexbuf[NSYMB];
EXTERN char debug[256];
......
......@@ -129,7 +129,8 @@ file:
if(debug['f'])
frame(1);
fninit($4);
testdclstack();
if(nsyntaxerrors == 0)
testdclstack();
}
package:
......
......@@ -144,6 +144,9 @@ slicerewrite(Node *n)
int b;
Node *a;
while(n->op == OCONVNOP)
n = n->left;
// call to newarray - find nel argument
nel = findarg(n, "nel", "newarray");
if(nel == N || !isslice(n->type))
......
......@@ -22,8 +22,10 @@ yyerror(char *fmt, ...)
va_start(arg, fmt);
vfprint(1, fmt, arg);
va_end(arg);
if(strcmp(fmt, "syntax error") == 0)
if(strcmp(fmt, "syntax error") == 0) {
nsyntaxerrors++;
print(" near %s", lexbuf);
}
print("\n");
if(debug['h'])
*(int*)0 = 0;
......@@ -670,6 +672,7 @@ opnames[] =
[OCOM] = "COM",
[OCONTINUE] = "CONTINUE",
[OCONV] = "CONV",
[OCONVNOP] = "CONVNOP",
[ODCLARG] = "DCLARG",
[ODCLFIELD] = "DCLFIELD",
[ODCLFUNC] = "DCLFUNC",
......
......@@ -618,6 +618,9 @@ loop:
goto nottop;
walkconv(n);
goto ret;
case OCONVNOP:
goto ret;
case OCOMPMAP:
case OCOMPSLICE:
......@@ -1284,10 +1287,8 @@ walkconv(Node *n)
if(!isinter(l->type))
yyerror("type assertion requires interface on left, have %T", l->type);
et = ifaceas1(t, l->type, 1);
if(et == I2Isame || et == E2Esame) {
n->op = OCONV;
if(et == I2Isame || et == E2Esame)
goto nop;
}
if(et != Inone) {
indir(n, ifacecvt(t, l, et));
return;
......@@ -1303,10 +1304,15 @@ walkconv(Node *n)
// no-op conversion
if(cvttype(t, l->type) == 1) {
nop:
if(l->op != ONAME) {
if(l->op == OLITERAL) {
indir(n, l);
n->type = t;
l->type = t;
return;
}
// leave OCONV node in place
// in case tree gets walked again.
// back end will ignore.
n->op = OCONVNOP;
return;
}
......@@ -3564,6 +3570,8 @@ colas(Node *nl, Node *nr)
// finish call - first half above
l = listfirst(&savel, &nl);
t = structfirst(&saver, getoutarg(t));
if(t == T)
return N;
while(l != N) {
a = mixedoldnew(l, t->type);
n = list(n, a);
......
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