Skip to content

Commit 06ef108

Browse files
cuonglmmdempsky
authored andcommitted
cmd/compile: fix unsafeValue handles OLSH/ORSH wrong
For OLSH/ORSH, the right node is not a uintptr-typed. However, unsafeValue still be called recursively for it, causing the compiler crashes. To fixing, the right node only needs to be evaluated for side-effects, so just discard its value. Fixes #32959 Change-Id: I34d5aa0823a0545f6dad1ec34774235ecf11addc Reviewed-on: https://go-review.googlesource.com/c/go/+/185039 Run-TryBot: Cuong Manh Le <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: David Chase <[email protected]> Reviewed-by: Matthew Dempsky <[email protected]>
1 parent a19c0ce commit 06ef108

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/cmd/compile/internal/gc/escape.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,9 +614,14 @@ func (e *Escape) unsafeValue(k EscHole, n *Node) {
614614
}
615615
case OPLUS, ONEG, OBITNOT:
616616
e.unsafeValue(k, n.Left)
617-
case OADD, OSUB, OOR, OXOR, OMUL, ODIV, OMOD, OLSH, ORSH, OAND, OANDNOT:
617+
case OADD, OSUB, OOR, OXOR, OMUL, ODIV, OMOD, OAND, OANDNOT:
618618
e.unsafeValue(k, n.Left)
619619
e.unsafeValue(k, n.Right)
620+
case OLSH, ORSH:
621+
e.unsafeValue(k, n.Left)
622+
// RHS need not be uintptr-typed (#32959) and can't meaningfully
623+
// flow pointers anyway.
624+
e.discard(n.Right)
620625
default:
621626
e.exprSkipInit(e.discardHole(), n)
622627
}

test/fixedbugs/issue32959.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// compile
2+
3+
// Copyright 2019 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+
// Test escape analysis with shifting constant
8+
9+
package main
10+
11+
import "unsafe"
12+
13+
func main() {
14+
var l uint64
15+
var p unsafe.Pointer
16+
_ = unsafe.Pointer(uintptr(p) + (uintptr(l) >> 1))
17+
}

0 commit comments

Comments
 (0)