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