| 1 |
// Copyright 2020 The Go Authors. All rights reserved. |
| 2 |
// Use of this source code is governed by a BSD-style |
| 3 |
// license that can be found in the LICENSE file. |
| 4 |
|
| 5 |
// Test that GC data is generated correctly for global |
| 6 |
// variables with types defined in a shared library. |
| 7 |
// See issue 39927. |
| 8 |
|
| 9 |
// This test run under GODEBUG=clobberfree=1. The check |
| 10 |
// *x[i] == 12345 depends on this debug mode to clobber |
| 11 |
// the value if the object is freed prematurely. |
| 12 |
|
| 13 |
package main |
| 14 |
|
| 15 |
import ( |
| 16 |
"fmt" |
| 17 |
"runtime" |
| 18 |
"testshared/gcdata/p" |
| 19 |
) |
| 20 |
|
| 21 |
var x p.T |
| 22 |
|
| 23 |
func main() { |
| 24 |
for i := range x { |
| 25 |
x[i] = new(int) |
| 26 |
*x[i] = 12345 |
| 27 |
} |
| 28 |
runtime.GC() |
| 29 |
runtime.GC() |
| 30 |
runtime.GC() |
| 31 |
for i := range x { |
| 32 |
if *x[i] != 12345 { |
| 33 |
fmt.Printf("x[%d] == %d, want 12345\n", i, *x[i]) |
| 34 |
panic("FAIL") |
| 35 |
} |
| 36 |
} |
| 37 |
} |