Source file test/fixedbugs/issue78081.go

     1  // run
     2  
     3  // Copyright 2026 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  package main
     8  
     9  import "runtime"
    10  
    11  func main() {
    12  	runtime.GOMAXPROCS(2)
    13  	c := make(chan bool)
    14  	for i := 0; i < 16; i++ {
    15  		go func() {
    16  			var b []byte
    17  			for range 100000 {
    18  				f(&b)
    19  			}
    20  			c <- true
    21  		}()
    22  	}
    23  	for i := 0; i < 16; i++ {
    24  		<-c
    25  	}
    26  }
    27  
    28  var n int = 64 // constant, but the compiler doesn't know that
    29  
    30  //go:noinline
    31  func f(sink *[]byte) {
    32  	useStack(64) // Use 64KB of stack, so that shrinking might happen below.
    33  
    34  	x := make([]int, n, 128)             // on stack
    35  	_ = append(x, make([]int, 128-n)...) // memclrNoHeapPointersPreemptible call is here
    36  
    37  	*sink = make([]byte, 1024) // make some garbage to cause GC
    38  }
    39  
    40  //go:noinline
    41  func useStack(depth int) {
    42  	var b [128]int
    43  	if depth == b[depth%len(b)] { // depth == 0
    44  		return
    45  	}
    46  	useStack(depth - 1)
    47  }
    48  

View as plain text