Source file test/live_uintptrkeepalive.go

     1  // errorcheck -0 -m -live -std
     2  
     3  //go:build !windows && !js && !wasip1
     4  
     5  // Copyright 2015 The Go Authors. All rights reserved.
     6  // Use of this source code is governed by a BSD-style
     7  // license that can be found in the LICENSE file.
     8  
     9  // Test escape analysis and liveness inferred for uintptrkeepalive functions.
    10  //
    11  // This behavior is enabled automatically for function declarations with no
    12  // bodies (assembly, linkname), as well as explicitly on complete functions
    13  // with //go:uintptrkeepalive.
    14  //
    15  // This is most important for syscall.Syscall (and similar functions), so we
    16  // test it explicitly.
    17  
    18  package p
    19  
    20  import (
    21  	"syscall"
    22  	"unsafe"
    23  )
    24  
    25  func implicit(uintptr) // ERROR "assuming ~p0 is unsafe uintptr"
    26  
    27  //go:uintptrkeepalive
    28  //go:nosplit
    29  func explicit(uintptr) {
    30  }
    31  
    32  func autotmpImplicit() { // ERROR "can inline autotmpImplicit"
    33  	var t int
    34  	implicit(uintptr(unsafe.Pointer(&t))) // ERROR "live at call to implicit: .?autotmp" "stack object .autotmp_[0-9]+ unsafe.Pointer$"
    35  }
    36  
    37  func autotmpExplicit() { // ERROR "can inline autotmpExplicit"
    38  	var t int
    39  	explicit(uintptr(unsafe.Pointer(&t))) // ERROR "live at call to explicit: .?autotmp" "stack object .autotmp_[0-9]+ unsafe.Pointer$"
    40  }
    41  
    42  func autotmpSyscall() { // ERROR "can inline autotmpSyscall"
    43  	var v int
    44  	syscall.Syscall(0, 1, uintptr(unsafe.Pointer(&v)), 2) // ERROR "live at call to Syscall: .?autotmp" "stack object .autotmp_[0-9]+ unsafe.Pointer$"
    45  }
    46  
    47  func localImplicit() { // ERROR "can inline localImplicit"
    48  	var t int
    49  	p := unsafe.Pointer(&t)
    50  	implicit(uintptr(p)) // ERROR "live at call to implicit: .?autotmp" "stack object .autotmp_[0-9]+ unsafe.Pointer$"
    51  }
    52  
    53  func localExplicit() { // ERROR "can inline localExplicit"
    54  	var t int
    55  	p := unsafe.Pointer(&t)
    56  	explicit(uintptr(p)) // ERROR "live at call to explicit: .?autotmp" "stack object .autotmp_[0-9]+ unsafe.Pointer$"
    57  }
    58  
    59  func localSyscall() { // ERROR "can inline localSyscall"
    60  	var v int
    61  	p := unsafe.Pointer(&v)
    62  	syscall.Syscall(0, 1, uintptr(p), 2) // ERROR "live at call to Syscall: .?autotmp" "stack object .autotmp_[0-9]+ unsafe.Pointer$"
    63  }
    64  

View as plain text