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 10package main 11 12import ( 13 "unsafe" 14) 15 16var badPtr uintptr 17 18var sink []byte 19 20func 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 28var throttle = make(chan struct{}, 10) 29 30// There are 2 arg bitmaps for this function, each with 2 bits. 31// In the first, p and q are both live, so that bitmap is 11. 32// In the second, only p is live, so that bitmap is 10. 33// Bitmaps are byte aligned, so if the first bitmap is interpreted as 34// extending across the entire argument area, we incorrectly concatenate 35// the bitmaps and end up using 110000001. That bad bitmap causes a6 36// to be considered a pointer. 37func noPointerArgs(p, q *byte, a0, a1, a2, a3, a4, a5, a6 uintptr) { 38 sink = make([]byte, 4096) 39 sinkptr = q 40 <-throttle 41 sinkptr = p 42} 43 44var sinkptr *byte 45 46func main() { 47 const N = 1000 48 for i := 0; i < N; i++ { 49 throttle <- struct{}{} 50 go noPointerArgs(nil, nil, badPtr, badPtr, badPtr, badPtr, badPtr, badPtr, badPtr) 51 sink = make([]byte, 4096) 52 } 53} 54