Source file test/fixedbugs/issue67255.go

     1  // run
     2  
     3  // Copyright 2024 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  var zero int
    10  
    11  var sink any
    12  
    13  func main() {
    14  	var objs [][]*byte
    15  	for i := 10; i < 200; i++ {
    16  		// The objects we're allocating here are pointer-ful. Some will
    17  		// max out their size class, which are the ones we want.
    18  		// We also allocate from small to large, so that the object which
    19  		// maxes out its size class is the last one allocated in that class.
    20  		// This allocation pattern leaves the next object in the class
    21  		// unallocated, which we need to reproduce the bug.
    22  		objs = append(objs, make([]*byte, i))
    23  	}
    24  	sink = objs // force heap allocation
    25  
    26  	// Bug will happen as soon as the write barrier turns on.
    27  	for range 10000 {
    28  		sink = make([]*byte, 1024)
    29  		for _, s := range objs {
    30  			s = append(s, make([]*byte, zero)...)
    31  		}
    32  	}
    33  }
    34  

View as plain text