Source file test/uintptrescapes.dir/a.go

     1  // Copyright 2016 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package a
     6  
     7  import (
     8  	"unsafe"
     9  )
    10  
    11  func recurse(i int, s []byte) byte {
    12  	s[0] = byte(i)
    13  	if i == 0 {
    14  		return s[i]
    15  	} else {
    16  		var a [1024]byte
    17  		r := recurse(i-1, a[:])
    18  		return r + a[0]
    19  	}
    20  }
    21  
    22  //go:uintptrescapes
    23  func F1(a uintptr) {
    24  	var s [16]byte
    25  	recurse(4096, s[:])
    26  	*(*int)(unsafe.Pointer(a)) = 42
    27  }
    28  
    29  //go:uintptrescapes
    30  func F2(a ...uintptr) {
    31  	var s [16]byte
    32  	recurse(4096, s[:])
    33  	*(*int)(unsafe.Pointer(a[0])) = 42
    34  }
    35  
    36  type t struct{}
    37  
    38  func GetT() *t {
    39  	return &t{}
    40  }
    41  
    42  //go:uintptrescapes
    43  func (*t) M1(a uintptr) {
    44  	var s [16]byte
    45  	recurse(4096, s[:])
    46  	*(*int)(unsafe.Pointer(a)) = 42
    47  }
    48  
    49  //go:uintptrescapes
    50  func (*t) M2(a ...uintptr) {
    51  	var s [16]byte
    52  	recurse(4096, s[:])
    53  	*(*int)(unsafe.Pointer(a[0])) = 42
    54  }
    55  

View as plain text