Source file test/fixedbugs/bug320.go
1 // run 2 3 // Copyright 2011 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 package main 8 9 func main() { 10 c := make(chan int, 1) 11 dummy := make(chan int) 12 v := 0x12345678 13 for i := 0; i < 10; i++ { 14 // 6g had a bug that caused select to pass &t to 15 // selectrecv before allocating the memory for t, 16 // which caused non-deterministic crashes. 17 // This test looks for the bug by checking that the 18 // value received actually ends up in t. 19 // If the allocation happens after storing through 20 // whatever garbage &t holds, the later reference 21 // to t in the case body will use the new pointer and 22 // not see the received value. 23 v += 0x1020304 24 c <- v 25 select { 26 case t := <-c: 27 go func() { 28 f(t) 29 }() 30 escape(&t) 31 if t != v { 32 println(i, v, t) 33 panic("wrong values") 34 } 35 case dummy <- 1: 36 } 37 } 38 } 39 40 func escape(*int) { 41 } 42 43 func f(int) { 44 } 45 46