diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-16 19:23:18 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-16 19:23:18 +0000 |
commit | 43a123c1ae6613b3efeed291fa552ecd909d3acf (patch) | |
tree | fd92518b7024bc74031f78a1cf9e454b65e73665 /misc/cgo/testshared/testdata/gcdata/main/main.go | |
parent | Initial commit. (diff) | |
download | golang-1.20-43a123c1ae6613b3efeed291fa552ecd909d3acf.tar.xz golang-1.20-43a123c1ae6613b3efeed291fa552ecd909d3acf.zip |
Adding upstream version 1.20.14.upstream/1.20.14upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'misc/cgo/testshared/testdata/gcdata/main/main.go')
-rw-r--r-- | misc/cgo/testshared/testdata/gcdata/main/main.go | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/misc/cgo/testshared/testdata/gcdata/main/main.go b/misc/cgo/testshared/testdata/gcdata/main/main.go new file mode 100644 index 0000000..394862f --- /dev/null +++ b/misc/cgo/testshared/testdata/gcdata/main/main.go @@ -0,0 +1,37 @@ +// Copyright 2020 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test that GC data is generated correctly for global +// variables with types defined in a shared library. +// See issue 39927. + +// This test run under GODEBUG=clobberfree=1. The check +// *x[i] == 12345 depends on this debug mode to clobber +// the value if the object is freed prematurely. + +package main + +import ( + "fmt" + "runtime" + "testshared/gcdata/p" +) + +var x p.T + +func main() { + for i := range x { + x[i] = new(int) + *x[i] = 12345 + } + runtime.GC() + runtime.GC() + runtime.GC() + for i := range x { + if *x[i] != 12345 { + fmt.Printf("x[%d] == %d, want 12345\n", i, *x[i]) + panic("FAIL") + } + } +} |