diff mbox

libgo patch committed: Fix reflect bug in method calls

Message ID mcra9jb14ji.fsf@iant-glaptop.roam.corp.google.com
State New
Headers show

Commit Message

Ian Lance Taylor Sept. 17, 2013, 10:12 p.m. UTC
This patch to libgo fixes a bug when calling a method when the
reflect.Value object holds a pointer to the actual value.  The code was
calling iword which tests v.kind, but for a method value that is always
Func.  This fixes the code to implement iword directly using
v.typ.Kind().  Bootstrapped and ran Go testsuite on
x86_64-unknown-linux-gnu.  Committed to mainline and 4.8 branch.

I added a test to the reflect testsuite in the master sources, and it
will be imported into the gccgo sources in due course.

Ian
diff mbox

Patch

Index: libgo/go/reflect/value.go
===================================================================
--- libgo/go/reflect/value.go	(revision 202233)
+++ libgo/go/reflect/value.go	(working copy)
@@ -611,7 +611,13 @@  func methodReceiver(op string, v Value,
 		}
 		fn = unsafe.Pointer(&m.tfn)
 		t = m.mtyp
-		rcvr = v.iword()
+		// Can't call iword here, because it checks v.kind,
+		// and that is always Func.
+		if v.flag&flagIndir != 0 && (v.typ.Kind() == Ptr || v.typ.Kind() == UnsafePointer) {
+			rcvr = loadIword(v.val, v.typ.size)
+		} else {
+			rcvr = iword(v.val)
+		}
 	}
 	return
 }