]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: allow huge rsh in constants arithmetic
authorAlberto Donizetti <alb.donizetti@gmail.com>
Thu, 20 Aug 2015 15:53:41 +0000 (17:53 +0200)
committerRobert Griesemer <gri@golang.org>
Fri, 21 Aug 2015 20:27:22 +0000 (20:27 +0000)
Currently an expression like

var v = 0 >> 1000

is rejected by gc with a "stupid shift" error, while gotype
compiles it successfully.

As suggested by gri on the issue tracker, allow an rsh right
operand to be any valid uint value.

Fixes #11328

Change-Id: I6ccb3b7f842338d91fd26ae37dd4fa279d7fc440
Reviewed-on: https://go-review.googlesource.com/13777
Reviewed-by: Robert Griesemer <gri@golang.org>
src/cmd/compile/internal/gc/mparith2.go
test/const.go

index 2c7e5176acb3a9a77930e86e521592b5b6f6c007..f70e342a961f64e6beb97124a48d5bb05986bbde 100644 (file)
@@ -229,7 +229,7 @@ func mprshfixfix(a, b *Mpint) {
        }
 
        s := Mpgetfix(b)
-       if s < 0 || s >= Mpprec {
+       if s < 0 {
                Yyerror("stupid shift: %d", s)
                if a.Val.Sign() < 0 {
                        Mpmovecfix(a, -1)
index d583659c6c30c2530aef72dc482dedc1a98c2ec8..6c29336396797280eb700d55429430fe81658e42 100644 (file)
@@ -19,6 +19,9 @@ const (
        c3div2  = 3 / 2
        c1e3    = 1e3
 
+       rsh1 = 1e100 >> 1000
+       rsh2 = 1e302 >> 1000
+
        ctrue  = true
        cfalse = !ctrue
 )
@@ -48,6 +51,8 @@ func ints() {
        assert(c3div2 == 1, "3/2")
        assert(c1e3 == 1000, "c1e3 int")
        assert(c1e3 == 1e3, "c1e3 float")
+       assert(rsh1 == 0, "rsh1")
+       assert(rsh2 == 9, "rsh2")
 
        // verify that all (in range) are assignable as ints
        var i int