diff options
author | Cherry Zhang <cherryyz@google.com> | 2021-04-19 17:37:25 -0400 |
---|---|---|
committer | Cherry Zhang <cherryyz@google.com> | 2021-04-20 14:30:03 +0000 |
commit | 3ff6ff7f8476b912ac6746c8e5afca852d62af7a (patch) | |
tree | cf392c880a897c64defa9e13bf60fb6054c5ea86 /test | |
parent | fe26dfadc3630617d133b8c94bcb2ccb2e85dc1b (diff) | |
download | go-3ff6ff7f8476b912ac6746c8e5afca852d62af7a.tar.gz go-3ff6ff7f8476b912ac6746c8e5afca852d62af7a.zip |
cmd/compile: preserve pointerness when creating map key temp
When creating the temporary for map functions, if the key
contains pointer, we need to create pointer-typed temporary. So
if the temporary is live across a function call, the pointer is
live.
Change-Id: Id6e14ec9def8bc7987f0f8ce8423caf1e3754fcb
Reviewed-on: https://go-review.googlesource.com/c/go/+/311379
Trust: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/abi/map.go | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/test/abi/map.go b/test/abi/map.go new file mode 100644 index 0000000000..236655a3af --- /dev/null +++ b/test/abi/map.go @@ -0,0 +1,34 @@ +// run + +// Copyright 2021 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. + +package main + +import "runtime" + +type T [10]int + +var m map[*T]int + +//go:noinline +func F() { + m = map[*T]int{ + K(): V(), // the key temp should be live across call to V + } +} + +//go:noinline +func V() int { runtime.GC(); runtime.GC(); runtime.GC(); return 123 } + +//go:noinline +func K() *T { + p := new(T) + runtime.SetFinalizer(p, func(*T) { println("FAIL") }) + return p +} + +func main() { + F() +} |