]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/asm: fix handling of negative shifts.
authorRob Pike <r@golang.org>
Mon, 22 Jun 2015 20:23:04 +0000 (06:23 +1000)
committerRob Pike <r@golang.org>
Mon, 22 Jun 2015 20:42:22 +0000 (20:42 +0000)
The change that "fixed" LSH was incorrect, and the fix for RSH was poor.
Make both use a correct, simple test: if the 64-bit value as a signed
integer is negative, it's an error.

Really fixes #11278.

Change-Id: I72cca03d7ad0d64fd649fa33a9ead2f31bd2977b
Reviewed-on: https://go-review.googlesource.com/11325
Reviewed-by: Andrew Gerrand <adg@golang.org>
src/cmd/asm/internal/asm/parse.go

index d7b52509139db246d2acc4ec1cbb9157fd15593d..18cc27fa83b4d90f8ad11b283ef24a8f37d77586 100644 (file)
@@ -807,16 +807,17 @@ func (p *Parser) term() uint64 {
                case lex.LSH:
                        p.next()
                        shift := p.factor()
-                       // shift is a uint, so can never be negative.
+                       if int64(shift) < 0 {
+                               p.errorf("left shift with high bit set")
+                       }
                        return value << shift
                case lex.RSH:
                        p.next()
                        shift := p.term()
-                       // shift is a uint, so can never be negative.
-                       if value&(1<<63) != 0 {
+                       if int64(shift) < 0 {
                                p.errorf("right shift with high bit set")
                        }
-                       value >>= uint(shift)
+                       value >>= shift
                case '&':
                        p.next()
                        value &= p.factor()