From: Martin Möhrmann Date: Fri, 7 Apr 2017 07:09:17 +0000 (+0200) Subject: cmd/compile: reduce reliance on implementation details of Mpint X-Git-Tag: go1.9beta1~793 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=ff3a4ef7ecabc651400e7b195c46739f6ad4b5e7;p=gostls13.git cmd/compile: reduce reliance on implementation details of Mpint Change-Id: Ifdc41f6c77c83d22b9ad8811280f1e1db051c781 Reviewed-on: https://go-review.googlesource.com/39951 Run-TryBot: Martin Möhrmann TryBot-Result: Gobot Gobot Reviewed-by: Robert Griesemer --- diff --git a/src/cmd/compile/internal/gc/const.go b/src/cmd/compile/internal/gc/const.go index 68d83bb962..e2193ea6ac 100644 --- a/src/cmd/compile/internal/gc/const.go +++ b/src/cmd/compile/internal/gc/const.go @@ -309,8 +309,9 @@ func convlit1(n *Node, t *types.Type, explicit bool, reuse canReuseNode) *Node { // if it is an unsafe.Pointer case TUINTPTR: if n.Type.Etype == TUNSAFEPTR { - n.SetVal(Val{new(Mpint)}) - n.Val().U.(*Mpint).SetInt64(0) + i := new(Mpint) + i.SetInt64(0) + n.SetVal(Val{i}) } else { goto bad } @@ -458,7 +459,7 @@ func toint(v Val) Val { case *Mpflt: i := new(Mpint) if !i.SetFloat(u) { - if i.Ovf { + if i.checkOverflow(0) { yyerror("integer too large") } else { // The value of u cannot be represented as an integer; @@ -1518,7 +1519,7 @@ func nonnegintconst(n *Node) int64 { // Mpint, so we still have to guard the conversion. v := toint(n.Val()) vi, ok := v.U.(*Mpint) - if !ok || vi.Val.Sign() < 0 || vi.Cmp(maxintval[TINT32]) > 0 { + if !ok || vi.CmpInt64(0) < 0 || vi.Cmp(maxintval[TINT32]) > 0 { return -1 } diff --git a/src/cmd/compile/internal/gc/mpfloat.go b/src/cmd/compile/internal/gc/mpfloat.go index 4ff7558357..a8a5335d36 100644 --- a/src/cmd/compile/internal/gc/mpfloat.go +++ b/src/cmd/compile/internal/gc/mpfloat.go @@ -38,7 +38,7 @@ func newMpflt() *Mpflt { } func (a *Mpflt) SetInt(b *Mpint) { - if b.Ovf { + if b.checkOverflow(0) { // sign doesn't really matter but copy anyway a.Val.SetInf(b.Val.Sign() < 0) return diff --git a/src/cmd/compile/internal/gc/swt_test.go b/src/cmd/compile/internal/gc/swt_test.go index 413989855c..74419596d2 100644 --- a/src/cmd/compile/internal/gc/swt_test.go +++ b/src/cmd/compile/internal/gc/swt_test.go @@ -5,16 +5,20 @@ package gc import ( - "math/big" "testing" ) func nodrune(r rune) *Node { - return nodlit(Val{&Mpint{Val: *big.NewInt(int64(r)), Rune: true}}) + v := new(Mpint) + v.SetInt64(int64(r)) + v.Rune = true + return nodlit(Val{v}) } func nodflt(f float64) *Node { - return nodlit(Val{&Mpflt{Val: *big.NewFloat(f)}}) + v := new(Mpflt) + v.SetFloat64(f) + return nodlit(Val{v}) } func TestCaseClauseByConstVal(t *testing.T) {