mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
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: Robert Griesemer <gri@golang.org>
This commit is contained in:
parent
63c1aff60b
commit
ff3a4ef7ec
3 changed files with 13 additions and 8 deletions
|
|
@ -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 {
|
||||||
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 {
|
||||||
// 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 {
|
||||||
}
|
}
|
||||||
|
|
||||||
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 @@
|
||||||
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) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue