Commit d08f34e7 authored by Marvin Stenger's avatar Marvin Stenger Committed by Brad Fitzpatrick

cmd/compile/internal/gc: convert return values from int to bool

Passes go build -toolexec 'toolstash -cmp' -a std.

Change-Id: I895350987661c1855803d1594dbab16068f8d1bc
Reviewed-on: https://go-review.googlesource.com/14873Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 8560ead3
...@@ -1160,16 +1160,16 @@ OpSwitch: ...@@ -1160,16 +1160,16 @@ OpSwitch:
} }
lo := n.Right.Left lo := n.Right.Left
if lo != nil && checksliceindex(l, lo, tp) < 0 { if lo != nil && !checksliceindex(l, lo, tp) {
n.Type = nil n.Type = nil
return return
} }
hi := n.Right.Right hi := n.Right.Right
if hi != nil && checksliceindex(l, hi, tp) < 0 { if hi != nil && !checksliceindex(l, hi, tp) {
n.Type = nil n.Type = nil
return return
} }
if checksliceconst(lo, hi) < 0 { if !checksliceconst(lo, hi) {
n.Type = nil n.Type = nil
return return
} }
...@@ -1227,21 +1227,21 @@ OpSwitch: ...@@ -1227,21 +1227,21 @@ OpSwitch:
} }
lo := n.Right.Left lo := n.Right.Left
if lo != nil && checksliceindex(l, lo, tp) < 0 { if lo != nil && !checksliceindex(l, lo, tp) {
n.Type = nil n.Type = nil
return return
} }
mid := n.Right.Right.Left mid := n.Right.Right.Left
if mid != nil && checksliceindex(l, mid, tp) < 0 { if mid != nil && !checksliceindex(l, mid, tp) {
n.Type = nil n.Type = nil
return return
} }
hi := n.Right.Right.Right hi := n.Right.Right.Right
if hi != nil && checksliceindex(l, hi, tp) < 0 { if hi != nil && !checksliceindex(l, hi, tp) {
n.Type = nil n.Type = nil
return return
} }
if checksliceconst(lo, hi) < 0 || checksliceconst(lo, mid) < 0 || checksliceconst(mid, hi) < 0 { if !checksliceconst(lo, hi) || !checksliceconst(lo, mid) || !checksliceconst(mid, hi) {
n.Type = nil n.Type = nil
return return
} }
...@@ -1300,7 +1300,7 @@ OpSwitch: ...@@ -1300,7 +1300,7 @@ OpSwitch:
n.Op = OCONV n.Op = OCONV
n.Type = l.Type n.Type = l.Type
if onearg(n, "conversion to %v", l.Type) < 0 { if !onearg(n, "conversion to %v", l.Type) {
n.Type = nil n.Type = nil
return return
} }
...@@ -1388,7 +1388,7 @@ OpSwitch: ...@@ -1388,7 +1388,7 @@ OpSwitch:
case OCAP, OLEN, OREAL, OIMAG: case OCAP, OLEN, OREAL, OIMAG:
ok |= Erv ok |= Erv
if onearg(n, "%v", Oconv(int(n.Op), 0)) < 0 { if !onearg(n, "%v", Oconv(int(n.Op), 0)) {
n.Type = nil n.Type = nil
return return
} }
...@@ -1484,7 +1484,7 @@ OpSwitch: ...@@ -1484,7 +1484,7 @@ OpSwitch:
l = t.Nname l = t.Nname
r = t.Down.Nname r = t.Down.Nname
} else { } else {
if twoarg(n) < 0 { if !twoarg(n) {
n.Type = nil n.Type = nil
return return
} }
...@@ -1538,7 +1538,7 @@ OpSwitch: ...@@ -1538,7 +1538,7 @@ OpSwitch:
break OpSwitch break OpSwitch
case OCLOSE: case OCLOSE:
if onearg(n, "%v", Oconv(int(n.Op), 0)) < 0 { if !onearg(n, "%v", Oconv(int(n.Op), 0)) {
n.Type = nil n.Type = nil
return return
} }
...@@ -1837,9 +1837,7 @@ OpSwitch: ...@@ -1837,9 +1837,7 @@ OpSwitch:
n.Type = nil n.Type = nil
return return
} }
et := obj.Bool2int(checkmake(t, "len", l) < 0) if !checkmake(t, "len", l) || r != nil && !checkmake(t, "cap", r) {
et |= obj.Bool2int(r != nil && checkmake(t, "cap", r) < 0)
if et != 0 {
n.Type = nil n.Type = nil
return return
} }
...@@ -1863,7 +1861,7 @@ OpSwitch: ...@@ -1863,7 +1861,7 @@ OpSwitch:
n.Type = nil n.Type = nil
return return
} }
if checkmake(t, "size", l) < 0 { if !checkmake(t, "size", l) {
n.Type = nil n.Type = nil
return return
} }
...@@ -1884,7 +1882,7 @@ OpSwitch: ...@@ -1884,7 +1882,7 @@ OpSwitch:
n.Type = nil n.Type = nil
return return
} }
if checkmake(t, "buffer", l) < 0 { if !checkmake(t, "buffer", l) {
n.Type = nil n.Type = nil
return return
} }
...@@ -1947,7 +1945,7 @@ OpSwitch: ...@@ -1947,7 +1945,7 @@ OpSwitch:
case OPANIC: case OPANIC:
ok |= Etop ok |= Etop
if onearg(n, "panic") < 0 { if !onearg(n, "panic") {
n.Type = nil n.Type = nil
return return
} }
...@@ -2228,42 +2226,42 @@ OpSwitch: ...@@ -2228,42 +2226,42 @@ OpSwitch:
*/ */
} }
func checksliceindex(l *Node, r *Node, tp *Type) int { func checksliceindex(l *Node, r *Node, tp *Type) bool {
t := r.Type t := r.Type
if t == nil { if t == nil {
return -1 return false
} }
if !Isint[t.Etype] { if !Isint[t.Etype] {
Yyerror("invalid slice index %v (type %v)", r, t) Yyerror("invalid slice index %v (type %v)", r, t)
return -1 return false
} }
if r.Op == OLITERAL { if r.Op == OLITERAL {
if Mpgetfix(r.Val().U.(*Mpint)) < 0 { if Mpgetfix(r.Val().U.(*Mpint)) < 0 {
Yyerror("invalid slice index %v (index must be non-negative)", r) Yyerror("invalid slice index %v (index must be non-negative)", r)
return -1 return false
} else if tp != nil && tp.Bound > 0 && Mpgetfix(r.Val().U.(*Mpint)) > tp.Bound { } else if tp != nil && tp.Bound > 0 && Mpgetfix(r.Val().U.(*Mpint)) > tp.Bound {
Yyerror("invalid slice index %v (out of bounds for %d-element array)", r, tp.Bound) Yyerror("invalid slice index %v (out of bounds for %d-element array)", r, tp.Bound)
return -1 return false
} else if Isconst(l, CTSTR) && Mpgetfix(r.Val().U.(*Mpint)) > int64(len(l.Val().U.(string))) { } else if Isconst(l, CTSTR) && Mpgetfix(r.Val().U.(*Mpint)) > int64(len(l.Val().U.(string))) {
Yyerror("invalid slice index %v (out of bounds for %d-byte string)", r, len(l.Val().U.(string))) Yyerror("invalid slice index %v (out of bounds for %d-byte string)", r, len(l.Val().U.(string)))
return -1 return false
} else if Mpcmpfixfix(r.Val().U.(*Mpint), Maxintval[TINT]) > 0 { } else if Mpcmpfixfix(r.Val().U.(*Mpint), Maxintval[TINT]) > 0 {
Yyerror("invalid slice index %v (index too large)", r) Yyerror("invalid slice index %v (index too large)", r)
return -1 return false
} }
} }
return 0 return true
} }
func checksliceconst(lo *Node, hi *Node) int { func checksliceconst(lo *Node, hi *Node) bool {
if lo != nil && hi != nil && lo.Op == OLITERAL && hi.Op == OLITERAL && Mpcmpfixfix(lo.Val().U.(*Mpint), hi.Val().U.(*Mpint)) > 0 { if lo != nil && hi != nil && lo.Op == OLITERAL && hi.Op == OLITERAL && Mpcmpfixfix(lo.Val().U.(*Mpint), hi.Val().U.(*Mpint)) > 0 {
Yyerror("invalid slice index: %v > %v", lo, hi) Yyerror("invalid slice index: %v > %v", lo, hi)
return -1 return false
} }
return 0 return true
} }
func checkdefergo(n *Node) { func checkdefergo(n *Node) {
...@@ -2341,14 +2339,14 @@ func implicitstar(nn **Node) { ...@@ -2341,14 +2339,14 @@ func implicitstar(nn **Node) {
*nn = n *nn = n
} }
func onearg(n *Node, f string, args ...interface{}) int { func onearg(n *Node, f string, args ...interface{}) bool {
if n.Left != nil { if n.Left != nil {
return 0 return true
} }
if n.List == nil { if n.List == nil {
p := fmt.Sprintf(f, args...) p := fmt.Sprintf(f, args...)
Yyerror("missing argument to %s: %v", p, n) Yyerror("missing argument to %s: %v", p, n)
return -1 return false
} }
if n.List.Next != nil { if n.List.Next != nil {
...@@ -2356,39 +2354,39 @@ func onearg(n *Node, f string, args ...interface{}) int { ...@@ -2356,39 +2354,39 @@ func onearg(n *Node, f string, args ...interface{}) int {
Yyerror("too many arguments to %s: %v", p, n) Yyerror("too many arguments to %s: %v", p, n)
n.Left = n.List.N n.Left = n.List.N
n.List = nil n.List = nil
return -1 return false
} }
n.Left = n.List.N n.Left = n.List.N
n.List = nil n.List = nil
return 0 return true
} }
func twoarg(n *Node) int { func twoarg(n *Node) bool {
if n.Left != nil { if n.Left != nil {
return 0 return true
} }
if n.List == nil { if n.List == nil {
Yyerror("missing argument to %v - %v", Oconv(int(n.Op), 0), n) Yyerror("missing argument to %v - %v", Oconv(int(n.Op), 0), n)
return -1 return false
} }
n.Left = n.List.N n.Left = n.List.N
if n.List.Next == nil { if n.List.Next == nil {
Yyerror("missing argument to %v - %v", Oconv(int(n.Op), 0), n) Yyerror("missing argument to %v - %v", Oconv(int(n.Op), 0), n)
n.List = nil n.List = nil
return -1 return false
} }
if n.List.Next.Next != nil { if n.List.Next.Next != nil {
Yyerror("too many arguments to %v - %v", Oconv(int(n.Op), 0), n) Yyerror("too many arguments to %v - %v", Oconv(int(n.Op), 0), n)
n.List = nil n.List = nil
return -1 return false
} }
n.Right = n.List.Next.N n.Right = n.List.Next.N
n.List = nil n.List = nil
return 0 return true
} }
func lookdot1(errnode *Node, s *Sym, t *Type, f *Type, dostrcmp int) *Type { func lookdot1(errnode *Node, s *Sym, t *Type, f *Type, dostrcmp int) *Type {
...@@ -3833,26 +3831,26 @@ ret: ...@@ -3833,26 +3831,26 @@ ret:
return n return n
} }
func checkmake(t *Type, arg string, n *Node) int { func checkmake(t *Type, arg string, n *Node) bool {
if n.Op == OLITERAL { if n.Op == OLITERAL {
switch n.Val().Ctype() { switch n.Val().Ctype() {
case CTINT, CTRUNE, CTFLT, CTCPLX: case CTINT, CTRUNE, CTFLT, CTCPLX:
n.SetVal(toint(n.Val())) n.SetVal(toint(n.Val()))
if mpcmpfixc(n.Val().U.(*Mpint), 0) < 0 { if mpcmpfixc(n.Val().U.(*Mpint), 0) < 0 {
Yyerror("negative %s argument in make(%v)", arg, t) Yyerror("negative %s argument in make(%v)", arg, t)
return -1 return false
} }
if Mpcmpfixfix(n.Val().U.(*Mpint), Maxintval[TINT]) > 0 { if Mpcmpfixfix(n.Val().U.(*Mpint), Maxintval[TINT]) > 0 {
Yyerror("%s argument too large in make(%v)", arg, t) Yyerror("%s argument too large in make(%v)", arg, t)
return -1 return false
} }
// Delay defaultlit until after we've checked range, to avoid // Delay defaultlit until after we've checked range, to avoid
// a redundant "constant NNN overflows int" error. // a redundant "constant NNN overflows int" error.
defaultlit(&n, Types[TINT]) defaultlit(&n, Types[TINT])
return 0 return true
default: default:
break break
...@@ -3861,13 +3859,13 @@ func checkmake(t *Type, arg string, n *Node) int { ...@@ -3861,13 +3859,13 @@ func checkmake(t *Type, arg string, n *Node) int {
if !Isint[n.Type.Etype] && n.Type.Etype != TIDEAL { if !Isint[n.Type.Etype] && n.Type.Etype != TIDEAL {
Yyerror("non-integer %s argument in make(%v) - %v", arg, t, n.Type) Yyerror("non-integer %s argument in make(%v) - %v", arg, t, n.Type)
return -1 return false
} }
// Defaultlit still necessary for non-constant: n might be 1<<k. // Defaultlit still necessary for non-constant: n might be 1<<k.
defaultlit(&n, Types[TINT]) defaultlit(&n, Types[TINT])
return 0 return true
} }
func markbreak(n *Node, implicit *Node) { func markbreak(n *Node, implicit *Node) {
......
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