]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: fix unsafe.Pointer liveness for Syscall-like functions
authorMatthew Dempsky <mdempsky@google.com>
Fri, 8 Dec 2017 07:04:50 +0000 (23:04 -0800)
committerMatthew Dempsky <mdempsky@google.com>
Fri, 8 Dec 2017 21:34:24 +0000 (21:34 +0000)
The package unsafe docs say it's safe to convert an unsafe.Pointer to
uintptr in the argument list to an assembly function, but it was
erroneously only detecting normal pointers converted to unsafe.Pointer
and then to intptr.

Fixes #23051.

Change-Id: Id1be19f6d8f26f2d17ba815191717d2f4f899732
Reviewed-on: https://go-review.googlesource.com/82817
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/cmd/compile/internal/gc/order.go
test/live_syscall.go

index de89adf0e0ebc0f1b31466eca610fc9028c21ccc..4b24be893a13b4c3eedf1ebab62d4215b9744233 100644 (file)
@@ -395,11 +395,11 @@ func ordercall(n *Node, order *Order) {
                        // by copying it into a temp and marking that temp
                        // still alive when we pop the temp stack.
                        xp := n.List.Addr(i)
-                       for (*xp).Op == OCONVNOP && !(*xp).Type.IsPtr() {
+                       for (*xp).Op == OCONVNOP && !(*xp).Type.IsUnsafePtr() {
                                xp = &(*xp).Left
                        }
                        x := *xp
-                       if x.Type.IsPtr() {
+                       if x.Type.IsUnsafePtr() {
                                x = ordercopyexpr(x, x.Type, order, 0)
                                x.Name.SetKeepalive(true)
                                *xp = x
index f693e9357a6734da124e638874ddb4acbd2149e6..6d954653cc5172a70fdd1a46f96096a2f01d27b1 100644 (file)
@@ -26,3 +26,15 @@ func h() {
        var v int
        syscall.Syscall(0, 1, uintptr(unsafe.Pointer(&v)), 2) // ERROR "live at call to Syscall: .?autotmp" "h &v does not escape"
 }
+
+func i() {
+       var t int
+       p := unsafe.Pointer(&t) // ERROR "i &t does not escape"
+       f(uintptr(p))           // ERROR "live at call to f: .?autotmp"
+}
+
+func j() {
+       var v int
+       p := unsafe.Pointer(&v)              // ERROR "j &v does not escape"
+       syscall.Syscall(0, 1, uintptr(p), 2) // ERROR "live at call to Syscall: .?autotmp"
+}