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 { ...@@ -3798,32 +3798,22 @@ func checkmake(t *Type, arg string, n *Node) bool {
return false return false
} }
if n.Op == OLITERAL { // Do range checks for constants before defaultlit
switch n.Val().Ctype() { // to avoid redundant "constant NNN overflows int" errors.
switch consttype(n) {
case CTINT, CTRUNE, CTFLT, CTCPLX: case CTINT, CTRUNE, CTFLT, CTCPLX:
n.SetVal(toint(n.Val())) n.SetVal(toint(n.Val()))
if n.Val().U.(*Mpint).CmpInt64(0) < 0 { if n.Val().U.(*Mpint).CmpInt64(0) < 0 {
yyerror("negative %s argument in make(%v)", arg, t) yyerror("negative %s argument in make(%v)", arg, t)
return false return false
} }
if n.Val().U.(*Mpint).Cmp(maxintval[TINT]) > 0 { if n.Val().U.(*Mpint).Cmp(maxintval[TINT]) > 0 {
yyerror("%s argument too large in make(%v)", arg, t) yyerror("%s argument too large in make(%v)", arg, t)
return false 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
}
} }
// 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]) n = defaultlit(n, Types[TINT])
return true 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