]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: reduce reliance on implementation details of Mpint
authorMartin Möhrmann <moehrmann@google.com>
Fri, 7 Apr 2017 07:09:17 +0000 (09:09 +0200)
committerRobert Griesemer <gri@golang.org>
Fri, 7 Apr 2017 17:08:34 +0000 (17:08 +0000)
Change-Id: Ifdc41f6c77c83d22b9ad8811280f1e1db051c781
Reviewed-on: https://go-review.googlesource.com/39951
Run-TryBot: Martin Möhrmann <moehrmann@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
src/cmd/compile/internal/gc/const.go
src/cmd/compile/internal/gc/mpfloat.go
src/cmd/compile/internal/gc/swt_test.go

index 68d83bb962ad0e08f6c183d4d13b6a1e78cae9c6..e2193ea6acff670b21c048ddf763eb2e7afe2fab 100644 (file)
@@ -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
        }
 
index 4ff755835705b1d6ee26485b4ac86569d62a5872..a8a5335d3699ebba1251eabfb0f8543a3c55c77e 100644 (file)
@@ -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
index 413989855cb8b657ac4d549a6802a49953cf5db3..74419596d2400b7648e4975eb4b6c2be957b46d2 100644 (file)
@@ -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) {