1
0
mirror of https://github.com/golang/go synced 2024-11-26 18:26:48 -07:00

cmd/compile: don't inline reflect.Value.UnsafeAddr/Pointer if enable checkptr

Fixes #35073

Change-Id: I4b555bbc33d39a97544e6dd9c61d95ae212f472b
Reviewed-on: https://go-review.googlesource.com/c/go/+/222878
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
Cuong Manh Le 2020-03-11 12:51:44 +07:00
parent afc480bab4
commit e9850462aa
2 changed files with 29 additions and 0 deletions

View File

@ -575,6 +575,12 @@ func inlnode(n *Node, maxCost int32) *Node {
// so escape analysis can avoid more heapmoves.
case OCLOSURE:
return n
case OCALLMETH:
// Prevent inlining some reflect.Value methods when using checkptr,
// even when package reflect was compiled without it (#35073).
if s := n.Left.Sym; Debug_checkptr != 0 && s.Pkg.Path == "reflect" && (s.Name == "Value.UnsafeAddr" || s.Name == "Value.Pointer") {
return n
}
}
lno := setlineno(n)

View File

@ -0,0 +1,23 @@
// run -gcflags=-d=checkptr
// 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 reflect.Value.UnsafeAddr/Pointer is handled
// correctly by -d=checkptr
package main
import (
"reflect"
"unsafe"
)
func main() {
n := 10
m := make(map[string]string)
_ = unsafe.Pointer(reflect.ValueOf(&n).Elem().UnsafeAddr())
_ = unsafe.Pointer(reflect.ValueOf(&m).Elem().Pointer())
}