reflect: fix methodValueCall code pointer mismatched

CL 322350 changed how to take address of assembly functions, using
abi.FuncPCABI0 intrinsic. But we forgot to update the code in
Value.UnsafePointer (was Value.Pointer) to reflect that change.

This CL fixes that bug, and also add a test to make sure the code
pointer is in sync.

Change-Id: I05ae7df31c706583a0f374d8af027066528f5ceb
Reviewed-on: https://go-review.googlesource.com/c/go/+/356809
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
diff --git a/src/reflect/all_test.go b/src/reflect/all_test.go
index 141cc8f..91aac9c 100644
--- a/src/reflect/all_test.go
+++ b/src/reflect/all_test.go
@@ -7722,3 +7722,11 @@
 	v = ValueOf((*nih)(unsafe.Pointer(new(int))))
 	shouldPanic("reflect: reflect.Value.Elem on an invalid notinheap pointer", func() { v.Elem() })
 }
+
+func TestMethodCallValueCodePtr(t *testing.T) {
+	p := ValueOf(Point{}).Method(1).UnsafePointer()
+	want := MethodValueCallCodePtr()
+	if got := uintptr(p); got != want {
+		t.Errorf("methodValueCall code pointer mismatched, want: %v, got: %v", want, got)
+	}
+}
diff --git a/src/reflect/export_test.go b/src/reflect/export_test.go
index 01749e3..ba7fb68 100644
--- a/src/reflect/export_test.go
+++ b/src/reflect/export_test.go
@@ -161,3 +161,5 @@
 	clearLayoutCache()
 	return
 }
+
+var MethodValueCallCodePtr = methodValueCallCodePtr
diff --git a/src/reflect/makefunc.go b/src/reflect/makefunc.go
index 588be8b..d0b0935 100644
--- a/src/reflect/makefunc.go
+++ b/src/reflect/makefunc.go
@@ -107,7 +107,7 @@
 	// v.Type returns the actual type of the method value.
 	ftyp := (*funcType)(unsafe.Pointer(v.Type().(*rtype)))
 
-	code := abi.FuncPCABI0(methodValueCall)
+	code := methodValueCallCodePtr()
 
 	// methodValue contains a stack map for use by the runtime
 	_, _, abi := funcLayout(ftyp, nil)
@@ -130,6 +130,10 @@
 	return Value{&ftyp.rtype, unsafe.Pointer(fv), v.flag&flagRO | flag(Func)}
 }
 
+func methodValueCallCodePtr() uintptr {
+	return abi.FuncPCABI0(methodValueCall)
+}
+
 // methodValueCall is an assembly function that is the code half of
 // the function returned from makeMethodValue. It expects a *methodValue
 // as its context register, and its job is to invoke callMethod(ctxt, frame)
diff --git a/src/reflect/value.go b/src/reflect/value.go
index a272714..1d385f6 100644
--- a/src/reflect/value.go
+++ b/src/reflect/value.go
@@ -2488,8 +2488,8 @@
 			// created via reflect have the same underlying code pointer,
 			// so their Pointers are equal. The function used here must
 			// match the one used in makeMethodValue.
-			f := methodValueCall
-			return **(**unsafe.Pointer)(unsafe.Pointer(&f))
+			code := methodValueCallCodePtr()
+			return *(*unsafe.Pointer)(unsafe.Pointer(&code))
 		}
 		p := v.pointer()
 		// Non-nil func value points at data block.