return tot
}
+// This will be index 5.
+func (p *Point) Int64Method(x int64) int64 {
+ return x
+}
+
+// This will be index 6.
+func (p *Point) Int32Method(x int32) int32 {
+ return x
+}
+
func TestMethod(t *testing.T) {
// Non-curried method of type.
p := Point{3, 4}
if i != 425 {
t.Errorf("Interface MethodByName returned %d; want 425", i)
}
+
+ // For issue #33628: method args are not stored at the right offset
+ // on amd64p32.
+ m64 := ValueOf(&p).MethodByName("Int64Method").Interface().(func(int64) int64)
+ if x := m64(123); x != 123 {
+ t.Errorf("Int64Method returned %d; want 123", x)
+ }
+ m32 := ValueOf(&p).MethodByName("Int32Method").Interface().(func(int32) int32)
+ if x := m32(456); x != 456 {
+ t.Errorf("Int32Method returned %d; want 456", x)
+ }
}
func TestVariadicMethodValue(t *testing.T) {
scratch := framePool.Get().(unsafe.Pointer)
// Copy in receiver and rest of args.
- // Avoid constructing out-of-bounds pointers if there are no args.
storeRcvr(rcvr, scratch)
- if argSize-ptrSize > 0 {
- typedmemmovepartial(frametype, add(scratch, ptrSize, "argSize > ptrSize"), frame, ptrSize, argSize-ptrSize)
+ // Align the first arg. Only on amd64p32 the alignment can be
+ // larger than ptrSize.
+ argOffset := uintptr(ptrSize)
+ if len(t.in()) > 0 {
+ argOffset = align(argOffset, uintptr(t.in()[0].align))
+ }
+ // Avoid constructing out-of-bounds pointers if there are no args.
+ if argSize-argOffset > 0 {
+ typedmemmovepartial(frametype, add(scratch, argOffset, "argSize > argOffset"), frame, argOffset, argSize-argOffset)
}
// Call.
// Ignore any changes to args and just copy return values.
// Avoid constructing out-of-bounds pointers if there are no return values.
if frametype.size-retOffset > 0 {
- callerRetOffset := retOffset - ptrSize
+ callerRetOffset := retOffset - argOffset
if runtime.GOARCH == "amd64p32" {
- callerRetOffset = align(argSize-ptrSize, 8)
+ callerRetOffset = align(argSize-argOffset, 8)
}
// This copies to the stack. Write barriers are not needed.
memmove(add(frame, callerRetOffset, "frametype.size > retOffset"),