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