1// errorcheck -0 -m -l
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 for runtime/internal/atomic.
8
9package escape
10
11import (
12	"runtime/internal/atomic"
13	"unsafe"
14)
15
16// BAD: should always be "leaking param: addr to result ~r0 level=1$".
17func Loadp(addr unsafe.Pointer) unsafe.Pointer { // ERROR "leaking param: addr( to result ~r0 level=1)?$"
18	return atomic.Loadp(addr)
19}
20
21var ptr unsafe.Pointer
22
23func Storep() {
24	var x int // ERROR "moved to heap: x"
25	atomic.StorepNoWB(unsafe.Pointer(&ptr), unsafe.Pointer(&x))
26}
27
28func Casp1() {
29	// BAD: should always be "does not escape"
30	x := new(int) // ERROR "escapes to heap|does not escape"
31	var y int     // ERROR "moved to heap: y"
32	atomic.Casp1(&ptr, unsafe.Pointer(x), unsafe.Pointer(&y))
33}
34