Source file test/escape_runtime_atomic.go

     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  
     9  package escape
    10  
    11  import (
    12  	"runtime/internal/atomic"
    13  	"unsafe"
    14  )
    15  
    16  // BAD: should always be "leaking param: addr to result ~r1 level=1$".
    17  func Loadp(addr unsafe.Pointer) unsafe.Pointer { // ERROR "leaking param: addr( to result ~r1 level=1)?$"
    18  	return atomic.Loadp(addr)
    19  }
    20  
    21  var ptr unsafe.Pointer
    22  
    23  func Storep() {
    24  	var x int // ERROR "moved to heap: x"
    25  	atomic.StorepNoWB(unsafe.Pointer(&ptr), unsafe.Pointer(&x))
    26  }
    27  
    28  func 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  

View as plain text