Source file test/fixedbugs/issue36516.go

     1  // run -race
     2  
     3  //go:build cgo && linux && amd64
     4  
     5  // Copyright 2020 The Go Authors. All rights reserved.
     6  // Use of this source code is governed by a BSD-style
     7  // license that can be found in the LICENSE file.
     8  
     9  package main
    10  
    11  import (
    12  	"fmt"
    13  	"testing"
    14  	"unsafe"
    15  )
    16  
    17  var buf [2]byte
    18  var x unsafe.Pointer = unsafe.Pointer(&buf[0])
    19  
    20  func main() {
    21  	n := testing.AllocsPerRun(1000, func() {
    22  		x = unsafe.Pointer(uintptr(x) + 1)
    23  		x = unsafe.Pointer(uintptr(x) - 1)
    24  	})
    25  	if n > 0 {
    26  		panic(fmt.Sprintf("too many allocations; want 0 got %f", n))
    27  	}
    28  }
    29  

View as plain text