Commit d1b14a6f authored by Russ Cox's avatar Russ Cox

gc: bug247, reported by rob

R=ken2
CC=golang-dev
https://golang.org/cl/194051
parent fd150e77
...@@ -330,7 +330,7 @@ evconst(Node *n) ...@@ -330,7 +330,7 @@ evconst(Node *n)
int32 len; int32 len;
Strlit *str; Strlit *str;
int wl, wr, lno, et; int wl, wr, lno, et;
Val v; Val v, rv;
Mpint b; Mpint b;
// pick off just the opcodes that can be // pick off just the opcodes that can be
...@@ -424,13 +424,15 @@ evconst(Node *n) ...@@ -424,13 +424,15 @@ evconst(Node *n)
if(wl == TIDEAL) if(wl == TIDEAL)
v = copyval(v); v = copyval(v);
rv = nr->val;
// since wl == wr, // since wl == wr,
// the only way v.ctype != nr->val.ctype // the only way v.ctype != nr->val.ctype
// is when one is CTINT and the other CTFLT. // is when one is CTINT and the other CTFLT.
// make both CTFLT. // make both CTFLT.
if(v.ctype != nr->val.ctype) { if(v.ctype != nr->val.ctype) {
v = toflt(v); v = toflt(v);
nr->val = toflt(nr->val); rv = toflt(rv);
} }
// run op // run op
...@@ -445,65 +447,65 @@ evconst(Node *n) ...@@ -445,65 +447,65 @@ evconst(Node *n)
return; return;
case TUP(OADD, CTINT): case TUP(OADD, CTINT):
mpaddfixfix(v.u.xval, nr->val.u.xval); mpaddfixfix(v.u.xval, rv.u.xval);
break; break;
case TUP(OSUB, CTINT): case TUP(OSUB, CTINT):
mpsubfixfix(v.u.xval, nr->val.u.xval); mpsubfixfix(v.u.xval, rv.u.xval);
break; break;
case TUP(OMUL, CTINT): case TUP(OMUL, CTINT):
mpmulfixfix(v.u.xval, nr->val.u.xval); mpmulfixfix(v.u.xval, rv.u.xval);
break; break;
case TUP(ODIV, CTINT): case TUP(ODIV, CTINT):
if(mpcmpfixc(nr->val.u.xval, 0) == 0) { if(mpcmpfixc(rv.u.xval, 0) == 0) {
yyerror("division by zero"); yyerror("division by zero");
mpmovecfix(v.u.xval, 1); mpmovecfix(v.u.xval, 1);
break; break;
} }
mpdivfixfix(v.u.xval, nr->val.u.xval); mpdivfixfix(v.u.xval, rv.u.xval);
break; break;
case TUP(OMOD, CTINT): case TUP(OMOD, CTINT):
if(mpcmpfixc(nr->val.u.xval, 0) == 0) { if(mpcmpfixc(rv.u.xval, 0) == 0) {
yyerror("division by zero"); yyerror("division by zero");
mpmovecfix(v.u.xval, 1); mpmovecfix(v.u.xval, 1);
break; break;
} }
mpmodfixfix(v.u.xval, nr->val.u.xval); mpmodfixfix(v.u.xval, rv.u.xval);
break; break;
case TUP(OLSH, CTINT): case TUP(OLSH, CTINT):
mplshfixfix(v.u.xval, nr->val.u.xval); mplshfixfix(v.u.xval, rv.u.xval);
break; break;
case TUP(ORSH, CTINT): case TUP(ORSH, CTINT):
mprshfixfix(v.u.xval, nr->val.u.xval); mprshfixfix(v.u.xval, rv.u.xval);
break; break;
case TUP(OOR, CTINT): case TUP(OOR, CTINT):
mporfixfix(v.u.xval, nr->val.u.xval); mporfixfix(v.u.xval, rv.u.xval);
break; break;
case TUP(OAND, CTINT): case TUP(OAND, CTINT):
mpandfixfix(v.u.xval, nr->val.u.xval); mpandfixfix(v.u.xval, rv.u.xval);
break; break;
case TUP(OANDNOT, CTINT): case TUP(OANDNOT, CTINT):
mpandnotfixfix(v.u.xval, nr->val.u.xval); mpandnotfixfix(v.u.xval, rv.u.xval);
break; break;
case TUP(OXOR, CTINT): case TUP(OXOR, CTINT):
mpxorfixfix(v.u.xval, nr->val.u.xval); mpxorfixfix(v.u.xval, rv.u.xval);
break; break;
case TUP(OADD, CTFLT): case TUP(OADD, CTFLT):
mpaddfltflt(v.u.fval, nr->val.u.fval); mpaddfltflt(v.u.fval, rv.u.fval);
break; break;
case TUP(OSUB, CTFLT): case TUP(OSUB, CTFLT):
mpsubfltflt(v.u.fval, nr->val.u.fval); mpsubfltflt(v.u.fval, rv.u.fval);
break; break;
case TUP(OMUL, CTFLT): case TUP(OMUL, CTFLT):
mpmulfltflt(v.u.fval, nr->val.u.fval); mpmulfltflt(v.u.fval, rv.u.fval);
break; break;
case TUP(ODIV, CTFLT): case TUP(ODIV, CTFLT):
if(mpcmpfltc(nr->val.u.fval, 0) == 0) { if(mpcmpfltc(rv.u.fval, 0) == 0) {
yyerror("division by zero"); yyerror("division by zero");
mpmovecflt(v.u.fval, 1.0); mpmovecflt(v.u.fval, 1.0);
break; break;
} }
mpdivfltflt(v.u.fval, nr->val.u.fval); mpdivfltflt(v.u.fval, rv.u.fval);
break; break;
case TUP(OEQ, CTNIL): case TUP(OEQ, CTNIL):
...@@ -512,52 +514,52 @@ evconst(Node *n) ...@@ -512,52 +514,52 @@ evconst(Node *n)
goto setfalse; goto setfalse;
case TUP(OEQ, CTINT): case TUP(OEQ, CTINT):
if(mpcmpfixfix(v.u.xval, nr->val.u.xval) == 0) if(mpcmpfixfix(v.u.xval, rv.u.xval) == 0)
goto settrue; goto settrue;
goto setfalse; goto setfalse;
case TUP(ONE, CTINT): case TUP(ONE, CTINT):
if(mpcmpfixfix(v.u.xval, nr->val.u.xval) != 0) if(mpcmpfixfix(v.u.xval, rv.u.xval) != 0)
goto settrue; goto settrue;
goto setfalse; goto setfalse;
case TUP(OLT, CTINT): case TUP(OLT, CTINT):
if(mpcmpfixfix(v.u.xval, nr->val.u.xval) < 0) if(mpcmpfixfix(v.u.xval, rv.u.xval) < 0)
goto settrue; goto settrue;
goto setfalse; goto setfalse;
case TUP(OLE, CTINT): case TUP(OLE, CTINT):
if(mpcmpfixfix(v.u.xval, nr->val.u.xval) <= 0) if(mpcmpfixfix(v.u.xval, rv.u.xval) <= 0)
goto settrue; goto settrue;
goto setfalse; goto setfalse;
case TUP(OGE, CTINT): case TUP(OGE, CTINT):
if(mpcmpfixfix(v.u.xval, nr->val.u.xval) >= 0) if(mpcmpfixfix(v.u.xval, rv.u.xval) >= 0)
goto settrue; goto settrue;
goto setfalse; goto setfalse;
case TUP(OGT, CTINT): case TUP(OGT, CTINT):
if(mpcmpfixfix(v.u.xval, nr->val.u.xval) > 0) if(mpcmpfixfix(v.u.xval, rv.u.xval) > 0)
goto settrue; goto settrue;
goto setfalse; goto setfalse;
case TUP(OEQ, CTFLT): case TUP(OEQ, CTFLT):
if(mpcmpfltflt(v.u.fval, nr->val.u.fval) == 0) if(mpcmpfltflt(v.u.fval, rv.u.fval) == 0)
goto settrue; goto settrue;
goto setfalse; goto setfalse;
case TUP(ONE, CTFLT): case TUP(ONE, CTFLT):
if(mpcmpfltflt(v.u.fval, nr->val.u.fval) != 0) if(mpcmpfltflt(v.u.fval, rv.u.fval) != 0)
goto settrue; goto settrue;
goto setfalse; goto setfalse;
case TUP(OLT, CTFLT): case TUP(OLT, CTFLT):
if(mpcmpfltflt(v.u.fval, nr->val.u.fval) < 0) if(mpcmpfltflt(v.u.fval, rv.u.fval) < 0)
goto settrue; goto settrue;
goto setfalse; goto setfalse;
case TUP(OLE, CTFLT): case TUP(OLE, CTFLT):
if(mpcmpfltflt(v.u.fval, nr->val.u.fval) <= 0) if(mpcmpfltflt(v.u.fval, rv.u.fval) <= 0)
goto settrue; goto settrue;
goto setfalse; goto setfalse;
case TUP(OGE, CTFLT): case TUP(OGE, CTFLT):
if(mpcmpfltflt(v.u.fval, nr->val.u.fval) >= 0) if(mpcmpfltflt(v.u.fval, rv.u.fval) >= 0)
goto settrue; goto settrue;
goto setfalse; goto setfalse;
case TUP(OGT, CTFLT): case TUP(OGT, CTFLT):
if(mpcmpfltflt(v.u.fval, nr->val.u.fval) > 0) if(mpcmpfltflt(v.u.fval, rv.u.fval) > 0)
goto settrue; goto settrue;
goto setfalse; goto setfalse;
...@@ -586,29 +588,29 @@ evconst(Node *n) ...@@ -586,29 +588,29 @@ evconst(Node *n)
goto settrue; goto settrue;
goto setfalse; goto setfalse;
case TUP(OADDSTR, CTSTR): case TUP(OADDSTR, CTSTR):
len = v.u.sval->len + nr->val.u.sval->len; len = v.u.sval->len + rv.u.sval->len;
str = mal(sizeof(*str) + len); str = mal(sizeof(*str) + len);
str->len = len; str->len = len;
memcpy(str->s, v.u.sval->s, v.u.sval->len); memcpy(str->s, v.u.sval->s, v.u.sval->len);
memcpy(str->s+v.u.sval->len, nr->val.u.sval->s, nr->val.u.sval->len); memcpy(str->s+v.u.sval->len, rv.u.sval->s, rv.u.sval->len);
str->len = len; str->len = len;
v.u.sval = str; v.u.sval = str;
break; break;
case TUP(OOROR, CTBOOL): case TUP(OOROR, CTBOOL):
if(v.u.bval || nr->val.u.bval) if(v.u.bval || rv.u.bval)
goto settrue; goto settrue;
goto setfalse; goto setfalse;
case TUP(OANDAND, CTBOOL): case TUP(OANDAND, CTBOOL):
if(v.u.bval && nr->val.u.bval) if(v.u.bval && rv.u.bval)
goto settrue; goto settrue;
goto setfalse; goto setfalse;
case TUP(OEQ, CTBOOL): case TUP(OEQ, CTBOOL):
if(v.u.bval == nr->val.u.bval) if(v.u.bval == rv.u.bval)
goto settrue; goto settrue;
goto setfalse; goto setfalse;
case TUP(ONE, CTBOOL): case TUP(ONE, CTBOOL):
if(v.u.bval != nr->val.u.bval) if(v.u.bval != rv.u.bval)
goto settrue; goto settrue;
goto setfalse; goto setfalse;
} }
......
// $G $D/$F.go && $L $F.$A && ./$A.out || echo BUG: bug247
// Copyright 2010 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
func main() {
const (
Delta = 100 * 1e6
Count = 10
)
_ = int64(Delta * Count)
var i interface{} = Count
j := i.(int)
if j != Count {
panicln("j=", j)
}
}
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