]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: ensure TESTQconst AuxInt is in range
authorJosh Bleecher Snyder <josharian@gmail.com>
Wed, 15 Mar 2017 18:27:26 +0000 (11:27 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Wed, 15 Mar 2017 21:44:08 +0000 (21:44 +0000)
Fixes #19555

Change-Id: I7aa0551a90f6bb630c0ba721f3525a8a9cf793fd
Reviewed-on: https://go-review.googlesource.com/38164
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
src/cmd/compile/internal/ssa/gen/AMD64.rules
src/cmd/compile/internal/ssa/rewriteAMD64.go
test/fixedbugs/issue19555.go [new file with mode: 0644]

index 3e68a2a73298da75ec79f0e9e437afec66ff4cc1..ca760cad1537ec9f8d6a141c13b1439a1c810957 100644 (file)
 (CMPBconst (ANDLconst [c] x) [0]) -> (TESTBconst [int64(int8(c))] x)
 
 // Convert TESTx to TESTxconst if possible.
-(TESTQ (MOVQconst [c]) x) && c < 1<<31 -> (TESTQconst [c] x)
+(TESTQ (MOVQconst [c]) x) && is32Bit(c) -> (TESTQconst [c] x)
 (TESTL (MOVLconst [c]) x) -> (TESTLconst [c] x)
 (TESTW (MOVLconst [c]) x) -> (TESTWconst [c] x)
 (TESTB (MOVLconst [c]) x) -> (TESTBconst [c] x)
-(TESTQ x (MOVQconst [c])) && c < 1<<31 -> (TESTQconst [c] x)
+(TESTQ x (MOVQconst [c])) && is32Bit(c) -> (TESTQconst [c] x)
 (TESTL x (MOVLconst [c])) -> (TESTLconst [c] x)
 (TESTW x (MOVLconst [c])) -> (TESTWconst [c] x)
 (TESTB x (MOVLconst [c])) -> (TESTBconst [c] x)
index 2a7291c502820d44c8161496f11f5929e16dec27..e581dfe5132631f6f84e06a83aba6132554a1fe0 100644 (file)
@@ -16360,7 +16360,7 @@ func rewriteValueAMD64_OpAMD64TESTQ(v *Value, config *Config) bool {
                return true
        }
        // match: (TESTQ (MOVQconst [c]) x)
-       // cond: c < 1<<31
+       // cond: is32Bit(c)
        // result: (TESTQconst [c] x)
        for {
                v_0 := v.Args[0]
@@ -16369,7 +16369,7 @@ func rewriteValueAMD64_OpAMD64TESTQ(v *Value, config *Config) bool {
                }
                c := v_0.AuxInt
                x := v.Args[1]
-               if !(c < 1<<31) {
+               if !(is32Bit(c)) {
                        break
                }
                v.reset(OpAMD64TESTQconst)
@@ -16378,7 +16378,7 @@ func rewriteValueAMD64_OpAMD64TESTQ(v *Value, config *Config) bool {
                return true
        }
        // match: (TESTQ x (MOVQconst [c]))
-       // cond: c < 1<<31
+       // cond: is32Bit(c)
        // result: (TESTQconst [c] x)
        for {
                x := v.Args[0]
@@ -16387,7 +16387,7 @@ func rewriteValueAMD64_OpAMD64TESTQ(v *Value, config *Config) bool {
                        break
                }
                c := v_1.AuxInt
-               if !(c < 1<<31) {
+               if !(is32Bit(c)) {
                        break
                }
                v.reset(OpAMD64TESTQconst)
diff --git a/test/fixedbugs/issue19555.go b/test/fixedbugs/issue19555.go
new file mode 100644 (file)
index 0000000..53b2ebd
--- /dev/null
@@ -0,0 +1,36 @@
+// compile
+
+// Copyright 2017 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
+
+type NodeLink struct{}
+
+// A role our end of NodeLink is intended to play
+type LinkRole int64
+
+const (
+       LinkServer LinkRole = iota // link created as server
+       LinkClient                 // link created as client
+
+       // for testing:
+       linkNoRecvSend LinkRole = 1 << 16 // do not spawn serveRecv & serveSend
+       linkFlagsMask  LinkRole = (1<<32 - 1) << 16
+)
+
+func NewNodeLink(role LinkRole) *NodeLink {
+       var nextConnId uint32
+       switch role &^ linkFlagsMask {
+       case LinkServer:
+               nextConnId = 0 // all initiated by us connId will be even
+       case LinkClient:
+               nextConnId = 1 // ----//---- odd
+       default:
+               panic("invalid conn role")
+       }
+
+       _ = nextConnId
+       return nil
+}