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 9package main 10 11import "runtime" 12import "unsafe" 13 14//go:registerparams 15func 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 26func G(int, int) {} 27 28//go:registerparams 29func GC() { runtime.GC(); runtime.GC() } 30 31func 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 41func poison([3]int) {} 42 43//go:noinline 44//go:registerparams 45func escape(s []int) { 46 g = s 47} 48var g []int 49