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