Skip to content

Commit

Permalink
cmd/compile: cleanup checkmake
Browse files Browse the repository at this point in the history
Change-Id: Icea4661db4a254e64b2129f429e5ef21ec1612cb
Reviewed-on: https://go-review.googlesource.com/32162
Run-TryBot: Martin Möhrmann <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
Reviewed-by: Josh Bleecher Snyder <[email protected]>
  • Loading branch information
martisch committed Oct 29, 2016
1 parent 023556c commit ee45711
Showing 1 changed file with 13 additions and 23 deletions.
36 changes: 13 additions & 23 deletions src/cmd/compile/internal/gc/typecheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -3798,32 +3798,22 @@ func checkmake(t *Type, arg string, n *Node) bool {
return false
}

if n.Op == OLITERAL {
switch n.Val().Ctype() {
case CTINT, CTRUNE, CTFLT, CTCPLX:
n.SetVal(toint(n.Val()))
if n.Val().U.(*Mpint).CmpInt64(0) < 0 {
yyerror("negative %s argument in make(%v)", arg, t)
return false
}

if n.Val().U.(*Mpint).Cmp(maxintval[TINT]) > 0 {
yyerror("%s argument too large in make(%v)", arg, t)
return false
}

// Delay defaultlit until after we've checked range, to avoid
// a redundant "constant NNN overflows int" error.
n = defaultlit(n, Types[TINT])

return true

default:
break
// Do range checks for constants before defaultlit
// to avoid redundant "constant NNN overflows int" errors.
switch consttype(n) {
case CTINT, CTRUNE, CTFLT, CTCPLX:
n.SetVal(toint(n.Val()))
if n.Val().U.(*Mpint).CmpInt64(0) < 0 {
yyerror("negative %s argument in make(%v)", arg, t)
return false
}
if n.Val().U.(*Mpint).Cmp(maxintval[TINT]) > 0 {
yyerror("%s argument too large in make(%v)", arg, t)
return false
}
}

// Defaultlit still necessary for non-constant: n might be 1<<k.
// defaultlit is necessary for non-constants too: n might be 1.1<<k.
n = defaultlit(n, Types[TINT])

return true
Expand Down

0 comments on commit ee45711

Please sign in to comment.