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:
parent
afc480bab4
commit
e9850462aa
@ -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)
|
||||
|
23
test/fixedbugs/issue35073.go
Normal file
23
test/fixedbugs/issue35073.go
Normal 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())
|
||||
}
|
Loading…
Reference in New Issue
Block a user