Commit ff3a4ef7 authored by Martin Möhrmann's avatar Martin Möhrmann Committed by Robert Griesemer

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 <moehrmann@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarRobert Griesemer <gri@golang.org>
parent 63c1aff6
...@@ -309,8 +309,9 @@ func convlit1(n *Node, t *types.Type, explicit bool, reuse canReuseNode) *Node { ...@@ -309,8 +309,9 @@ func convlit1(n *Node, t *types.Type, explicit bool, reuse canReuseNode) *Node {
// if it is an unsafe.Pointer // if it is an unsafe.Pointer
case TUINTPTR: case TUINTPTR:
if n.Type.Etype == TUNSAFEPTR { if n.Type.Etype == TUNSAFEPTR {
n.SetVal(Val{new(Mpint)}) i := new(Mpint)
n.Val().U.(*Mpint).SetInt64(0) i.SetInt64(0)
n.SetVal(Val{i})
} else { } else {
goto bad goto bad
} }
...@@ -458,7 +459,7 @@ func toint(v Val) Val { ...@@ -458,7 +459,7 @@ func toint(v Val) Val {
case *Mpflt: case *Mpflt:
i := new(Mpint) i := new(Mpint)
if !i.SetFloat(u) { if !i.SetFloat(u) {
if i.Ovf { if i.checkOverflow(0) {
yyerror("integer too large") yyerror("integer too large")
} else { } else {
// The value of u cannot be represented as an integer; // The value of u cannot be represented as an integer;
...@@ -1518,7 +1519,7 @@ func nonnegintconst(n *Node) int64 { ...@@ -1518,7 +1519,7 @@ func nonnegintconst(n *Node) int64 {
// Mpint, so we still have to guard the conversion. // Mpint, so we still have to guard the conversion.
v := toint(n.Val()) v := toint(n.Val())
vi, ok := v.U.(*Mpint) 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 return -1
} }
......
...@@ -38,7 +38,7 @@ func newMpflt() *Mpflt { ...@@ -38,7 +38,7 @@ func newMpflt() *Mpflt {
} }
func (a *Mpflt) SetInt(b *Mpint) { func (a *Mpflt) SetInt(b *Mpint) {
if b.Ovf { if b.checkOverflow(0) {
// sign doesn't really matter but copy anyway // sign doesn't really matter but copy anyway
a.Val.SetInf(b.Val.Sign() < 0) a.Val.SetInf(b.Val.Sign() < 0)
return return
......
...@@ -5,16 +5,20 @@ ...@@ -5,16 +5,20 @@
package gc package gc
import ( import (
"math/big"
"testing" "testing"
) )
func nodrune(r rune) *Node { 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 { 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) { func TestCaseClauseByConstVal(t *testing.T) {
......
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