package main
import (
"sync/atomic"
)
type Object struct{}
func main() {
println(test1())
println(test2())
println(test3())
println(test4())
}
func test1() int {
var x atomic.Int32
x.Store(1)
return int(x.Load())
}
func test2() string {
var x atomic.Value
x.Store("foo")
return x.Load().(string)
}
func test3() *Object {
var x atomic.Value
x.Store(&Object{})
return x.Load().(*Object)
}
func test4() bool {
var x atomic.Bool
x.Store(true)
return x.Load()
}
# command-line-arguments
./main.go:19:9: inlining call to atomic.(*Int32).Store
./main.go:20:19: inlining call to atomic.(*Int32).Load
./main.go:27:15: inlining call to atomic.(*Value).Load <-- here
./main.go:34:15: inlining call to atomic.(*Value).Load <-- here too
./main.go:40:9: inlining call to atomic.(*Bool).Store
./main.go:41:15: inlining call to atomic.(*Bool).Load
./main.go:40:9: inlining call to atomic.b32
./main.go:18:6: moved to heap: x
./main.go:25:6: moved to heap: x
./main.go:26:10: "foo" escapes to heap
./main.go:32:6: moved to heap: x
./main.go:33:10: &Object{} escapes to heap
./main.go:39:6: moved to heap: x
1
foo
0x50fdc0
true