Source file
test/fixedbugs/issue30041.go
1
2
3
4
5
6
7
8
9
10 package main
11
12 import (
13 "reflect"
14 "runtime"
15 "unsafe"
16 )
17
18 var badPtr uintptr
19
20 var sink []byte
21
22 func init() {
23
24 b := make([]byte, 1<<16-1)
25 sink = b
26
27 badPtr = uintptr(unsafe.Pointer(&b[len(b)-1])) + 1
28 }
29
30 type ft func() *int
31
32 var fn ft
33
34 func rf([]reflect.Value) []reflect.Value {
35 a := reflect.ValueOf((*int)(nil))
36 return []reflect.Value{a}
37 }
38
39 const N = 1000
40
41 func main() {
42 fn = reflect.MakeFunc(reflect.TypeOf(fn), rf).Interface().(ft)
43
44
45 go func() {
46 for i := 0; i < N; i++ {
47 runtime.GC()
48 }
49 }()
50
51 var x [10]uintptr
52 for i := range x {
53 x[i] = badPtr
54 }
55 for i := 0; i < N; i++ {
56 runtime.Gosched()
57 use(x)
58 fn()
59 }
60 }
61
62
63 func use([10]uintptr) {}
64
View as plain text