Source file test/abi/part_live.go

     1  // run
     2  
     3  // Copyright 2021 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  // A test for partial liveness / partial spilling / compiler-induced GC failure
     8  
     9  package main
    10  
    11  import "runtime"
    12  import "unsafe"
    13  
    14  //go:registerparams
    15  func F(s []int) {
    16  	for i, x := range s {
    17  		G(i, x)
    18  	}
    19  	GC()
    20  	G(len(s), cap(s))
    21  	GC()
    22  }
    23  
    24  //go:noinline
    25  //go:registerparams
    26  func G(int, int) {}
    27  
    28  //go:registerparams
    29  func GC() { runtime.GC(); runtime.GC() }
    30  
    31  func main() {
    32  	s := make([]int, 3)
    33  	escape(s)
    34  	p := int(uintptr(unsafe.Pointer(&s[2])) + 42) // likely point to unallocated memory
    35  	poison([3]int{p, p, p})
    36  	F(s)
    37  }
    38  
    39  //go:noinline
    40  //go:registerparams
    41  func poison([3]int) {}
    42  
    43  //go:noinline
    44  //go:registerparams
    45  func escape(s []int) {
    46  	g = s
    47  }
    48  var g []int
    49  

View as plain text