]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: refactor detecting package reflect logic
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Sun, 19 Apr 2020 15:18:15 +0000 (22:18 +0700)
committerCuong Manh Le <cuong.manhle.vn@gmail.com>
Mon, 20 Apr 2020 02:39:16 +0000 (02:39 +0000)
Passes toolstash-check.

Change-Id: Ie4b1f61528bb183dc66bb6955851a47b2641549c
Reviewed-on: https://go-review.googlesource.com/c/go/+/228859
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
src/cmd/compile/internal/gc/go.go
src/cmd/compile/internal/gc/inl.go
src/cmd/compile/internal/gc/walk.go

index a7fdfd5b7a345fb61af5115636fc024787f2b08d..758c90931ff358debc3a6807fc726a8400c00fad 100644 (file)
@@ -45,6 +45,18 @@ func isRuntimePkg(p *types.Pkg) bool {
        return p.Path == "runtime"
 }
 
+// isReflectPkg reports whether p is package reflect.
+func isReflectPkg(p *types.Pkg) bool {
+       // TODO(cuonglm): how to get rid this check.
+       if p == nil {
+               return false
+       }
+       if p == localpkg {
+               return myimportpath == "reflect"
+       }
+       return p.Path == "reflect"
+}
+
 // The Class of a variable/function describes the "storage class"
 // of a variable or function. During parsing, storage classes are
 // called declaration contexts.
index 272d0bdab7b0d4ca0fb7b9a01b53b3721f38be31..fa5b3ec698be297a6b704df69af5c5f0cc0cd731 100644 (file)
@@ -585,7 +585,7 @@ func inlnode(n *Node, maxCost int32, inlMap map[*Node]bool) *Node {
        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") {
+               if s := n.Left.Sym; Debug_checkptr != 0 && isReflectPkg(s.Pkg) && (s.Name == "Value.UnsafeAddr" || s.Name == "Value.Pointer") {
                        return n
                }
        }
index 8ad7f6ace8d123a1c9eaad6d95180e1ad902c027..3a2a97373d9fcb789e6445e6d38ac25f798a5b2e 100644 (file)
@@ -3659,7 +3659,7 @@ func usemethod(n *Node) {
        // Note: Don't rely on res0.Type.String() since its formatting depends on multiple factors
        //       (including global variables such as numImports - was issue #19028).
        // Also need to check for reflect package itself (see Issue #38515).
-       if s := res0.Type.Sym; s != nil && s.Name == "Method" && s.Pkg != nil && (s.Pkg.Path == "reflect" || s.Pkg == localpkg && myimportpath == "reflect") {
+       if s := res0.Type.Sym; s != nil && s.Name == "Method" && isReflectPkg(s.Pkg) {
                Curfn.Func.SetReflectMethod(true)
        }
 }