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.
7 // Test escape analysis for sync/atomic.
16 // BAD: should be "leaking param content".
17 func LoadPointer(addr *unsafe.Pointer) unsafe.Pointer { // ERROR "leaking param: addr"
18 return atomic.LoadPointer(addr)
21 var ptr unsafe.Pointer
24 var x int // ERROR "moved to heap: x"
25 atomic.StorePointer(&ptr, unsafe.Pointer(&x))
29 var x int // ERROR "moved to heap: x"
30 atomic.SwapPointer(&ptr, unsafe.Pointer(&x))
33 func CompareAndSwapPointer() {
34 // BAD: x doesn't need to be heap allocated
35 var x int // ERROR "moved to heap: x"
36 var y int // ERROR "moved to heap: y"
37 atomic.CompareAndSwapPointer(&ptr, unsafe.Pointer(&x), unsafe.Pointer(&y))