Skip to content

Commit 840fad1

Browse files
committed
cmd/compile: fix unsafe.Pointer liveness for Syscall-like functions
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent a941028 commit 840fad1

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -395,11 +395,11 @@ func ordercall(n *Node, order *Order) {
395395
// by copying it into a temp and marking that temp
396396
// still alive when we pop the temp stack.
397397
xp := n.List.Addr(i)
398-
for (*xp).Op == OCONVNOP && !(*xp).Type.IsPtr() {
398+
for (*xp).Op == OCONVNOP && !(*xp).Type.IsUnsafePtr() {
399399
xp = &(*xp).Left
400400
}
401401
x := *xp
402-
if x.Type.IsPtr() {
402+
if x.Type.IsUnsafePtr() {
403403
x = ordercopyexpr(x, x.Type, order, 0)
404404
x.Name.SetKeepalive(true)
405405
*xp = x

test/live_syscall.go

+12
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,15 @@ func h() {
2626
var v int
2727
syscall.Syscall(0, 1, uintptr(unsafe.Pointer(&v)), 2) // ERROR "live at call to Syscall: .?autotmp" "h &v does not escape"
2828
}
29+
30+
func i() {
31+
var t int
32+
p := unsafe.Pointer(&t) // ERROR "i &t does not escape"
33+
f(uintptr(p)) // ERROR "live at call to f: .?autotmp"
34+
}
35+
36+
func j() {
37+
var v int
38+
p := unsafe.Pointer(&v) // ERROR "j &v does not escape"
39+
syscall.Syscall(0, 1, uintptr(p), 2) // ERROR "live at call to Syscall: .?autotmp"
40+
}

0 commit comments

Comments
 (0)