Skip to content

Commit 604455a

Browse files
committed
cmd/compile: ensure TESTQconst AuxInt is in range
Fixes #19555 Change-Id: I7aa0551a90f6bb630c0ba721f3525a8a9cf793fd Reviewed-on: https://go-review.googlesource.com/38164 Run-TryBot: Josh Bleecher Snyder <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Keith Randall <[email protected]>
1 parent d0a045d commit 604455a

File tree

3 files changed

+42
-6
lines changed

3 files changed

+42
-6
lines changed

src/cmd/compile/internal/ssa/gen/AMD64.rules

+2-2
Original file line numberDiff line numberDiff line change
@@ -1406,11 +1406,11 @@
14061406
(CMPBconst (ANDLconst [c] x) [0]) -> (TESTBconst [int64(int8(c))] x)
14071407

14081408
// Convert TESTx to TESTxconst if possible.
1409-
(TESTQ (MOVQconst [c]) x) && c < 1<<31 -> (TESTQconst [c] x)
1409+
(TESTQ (MOVQconst [c]) x) && is32Bit(c) -> (TESTQconst [c] x)
14101410
(TESTL (MOVLconst [c]) x) -> (TESTLconst [c] x)
14111411
(TESTW (MOVLconst [c]) x) -> (TESTWconst [c] x)
14121412
(TESTB (MOVLconst [c]) x) -> (TESTBconst [c] x)
1413-
(TESTQ x (MOVQconst [c])) && c < 1<<31 -> (TESTQconst [c] x)
1413+
(TESTQ x (MOVQconst [c])) && is32Bit(c) -> (TESTQconst [c] x)
14141414
(TESTL x (MOVLconst [c])) -> (TESTLconst [c] x)
14151415
(TESTW x (MOVLconst [c])) -> (TESTWconst [c] x)
14161416
(TESTB x (MOVLconst [c])) -> (TESTBconst [c] x)

src/cmd/compile/internal/ssa/rewriteAMD64.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -16360,7 +16360,7 @@ func rewriteValueAMD64_OpAMD64TESTQ(v *Value, config *Config) bool {
1636016360
return true
1636116361
}
1636216362
// match: (TESTQ (MOVQconst [c]) x)
16363-
// cond: c < 1<<31
16363+
// cond: is32Bit(c)
1636416364
// result: (TESTQconst [c] x)
1636516365
for {
1636616366
v_0 := v.Args[0]
@@ -16369,7 +16369,7 @@ func rewriteValueAMD64_OpAMD64TESTQ(v *Value, config *Config) bool {
1636916369
}
1637016370
c := v_0.AuxInt
1637116371
x := v.Args[1]
16372-
if !(c < 1<<31) {
16372+
if !(is32Bit(c)) {
1637316373
break
1637416374
}
1637516375
v.reset(OpAMD64TESTQconst)
@@ -16378,7 +16378,7 @@ func rewriteValueAMD64_OpAMD64TESTQ(v *Value, config *Config) bool {
1637816378
return true
1637916379
}
1638016380
// match: (TESTQ x (MOVQconst [c]))
16381-
// cond: c < 1<<31
16381+
// cond: is32Bit(c)
1638216382
// result: (TESTQconst [c] x)
1638316383
for {
1638416384
x := v.Args[0]
@@ -16387,7 +16387,7 @@ func rewriteValueAMD64_OpAMD64TESTQ(v *Value, config *Config) bool {
1638716387
break
1638816388
}
1638916389
c := v_1.AuxInt
16390-
if !(c < 1<<31) {
16390+
if !(is32Bit(c)) {
1639116391
break
1639216392
}
1639316393
v.reset(OpAMD64TESTQconst)

test/fixedbugs/issue19555.go

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// compile
2+
3+
// Copyright 2017 The Go Authors. All rights reserved.
4+
// Use of this source code is governed by a BSD-style
5+
// license that can be found in the LICENSE file.
6+
7+
package p
8+
9+
type NodeLink struct{}
10+
11+
// A role our end of NodeLink is intended to play
12+
type LinkRole int64
13+
14+
const (
15+
LinkServer LinkRole = iota // link created as server
16+
LinkClient // link created as client
17+
18+
// for testing:
19+
linkNoRecvSend LinkRole = 1 << 16 // do not spawn serveRecv & serveSend
20+
linkFlagsMask LinkRole = (1<<32 - 1) << 16
21+
)
22+
23+
func NewNodeLink(role LinkRole) *NodeLink {
24+
var nextConnId uint32
25+
switch role &^ linkFlagsMask {
26+
case LinkServer:
27+
nextConnId = 0 // all initiated by us connId will be even
28+
case LinkClient:
29+
nextConnId = 1 // ----//---- odd
30+
default:
31+
panic("invalid conn role")
32+
}
33+
34+
_ = nextConnId
35+
return nil
36+
}

0 commit comments

Comments
 (0)