Source file test/fixedbugs/issue29362.go

     1  // run
     2  
     3  // Copyright 2018 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  // Verify that we don't consider a Go'd function's
     8  // arguments as pointers when they aren't.
     9  
    10  package main
    11  
    12  import (
    13  	"unsafe"
    14  )
    15  
    16  var badPtr uintptr
    17  
    18  var sink []byte
    19  
    20  func init() {
    21  	// Allocate large enough to use largeAlloc.
    22  	b := make([]byte, 1<<16-1)
    23  	sink = b // force heap allocation
    24  	//  Any space between the object and the end of page is invalid to point to.
    25  	badPtr = uintptr(unsafe.Pointer(&b[len(b)-1])) + 1
    26  }
    27  
    28  var throttle = make(chan struct{}, 10)
    29  
    30  func noPointerArgs(a, b, c, d uintptr) {
    31  	sink = make([]byte, 4096)
    32  	<-throttle
    33  }
    34  
    35  func main() {
    36  	const N = 1000
    37  	for i := 0; i < N; i++ {
    38  		throttle <- struct{}{}
    39  		go noPointerArgs(badPtr, badPtr, badPtr, badPtr)
    40  		sink = make([]byte, 4096)
    41  	}
    42  }
    43  

View as plain text