| 1 |
// run |
| 2 |
|
| 3 |
// Copyright 2016 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 |
// Test to make sure we don't think values are dead |
| 8 |
// when they are assigned to a PPARAMOUT slot before |
| 9 |
// the last GC safepoint. |
| 10 |
|
| 11 |
package main |
| 12 |
|
| 13 |
import ( |
| 14 |
"fmt" |
| 15 |
"runtime" |
| 16 |
) |
| 17 |
|
| 18 |
// When a T is deallocated, T[1] is certain to |
| 19 |
// get clobbered (the runtime writes 0xdeaddeaddeaddead there). |
| 20 |
type T [4]int |
| 21 |
|
| 22 |
func f() (r, s *T) { |
| 23 |
r = &T{0x30, 0x31, 0x32, 0x33} |
| 24 |
runtime.GC() |
| 25 |
s = &T{0x40, 0x41, 0x42, 0x43} |
| 26 |
runtime.GC() |
| 27 |
return |
| 28 |
} |
| 29 |
|
| 30 |
func main() { |
| 31 |
r, s := f() |
| 32 |
if r[1] != 0x31 { |
| 33 |
fmt.Printf("bad r[1], want 0x31 got %x\n", r[1]) |
| 34 |
} |
| 35 |
if s[1] != 0x41 { |
| 36 |
fmt.Printf("bad s[1], want 0x41 got %x\n", s[1]) |
| 37 |
} |
| 38 |
} |