Commit ee457118 authored by Martin Möhrmann's avatar Martin Möhrmann Committed by Martin Möhrmann

cmd/compile: cleanup checkmake

Change-Id: Icea4661db4a254e64b2129f429e5ef21ec1612cb
Reviewed-on: https://go-review.googlesource.com/32162
Run-TryBot: Martin Möhrmann <martisch@uos.de>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarJosh Bleecher Snyder <josharian@gmail.com>
parent 023556c0
......@@ -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
......
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