Skip to content

Commit

Permalink
cmd/compile: fix value range check for complex constants
Browse files Browse the repository at this point in the history
Fixes #11590.

Change-Id: I4144107334604a2cc98c7984df3b5d4cde3d30af
Reviewed-on: https://go-review.googlesource.com/16920
Reviewed-by: Ian Lance Taylor <iant@golang.org>
  • Loading branch information
rsc committed Nov 16, 2015
1 parent 292ad59 commit 2c11164
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/cmd/compile/internal/gc/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,6 @@ func convlit1(np **Node, t *Type, explicit bool) {
n.SetVal(toint(n.Val()))
fallthrough

// flowthrough
case CTINT:
overflow(n.Val(), t)
}
Expand All @@ -272,7 +271,6 @@ func convlit1(np **Node, t *Type, explicit bool) {
n.SetVal(toflt(n.Val()))
fallthrough

// flowthrough
case CTFLT:
n.SetVal(Val{truncfltlit(n.Val().U.(*Mpflt), t)})
}
Expand All @@ -283,6 +281,7 @@ func convlit1(np **Node, t *Type, explicit bool) {

case CTFLT, CTINT, CTRUNE:
n.SetVal(tocplx(n.Val()))
fallthrough

case CTCPLX:
overflow(n.Val(), t)
Expand Down
11 changes: 11 additions & 0 deletions test/fixedbugs/issue11590.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// errorcheck

// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package p

var _ = int8(4) * 300 // ERROR "constant overflows int8"
var _ = complex64(1) * 1e200 // ERROR "constant overflows complex64"
var _ = complex128(1) * 1e500 // ERROR "constant overflows complex128"

0 comments on commit 2c11164

Please sign in to comment.