diff mbox series

libgo patch committed: Fix hash/string values computed by reflect.StructOf

Message ID CAOyqgcUtcsLyVROCMhytftO=qAAhb=Rp6UNYO3OM9py8ABPpvA@mail.gmail.com
State New
Headers show
Series libgo patch committed: Fix hash/string values computed by reflect.StructOf | expand

Commit Message

Ian Lance Taylor June 6, 2018, 2:50 p.m. UTC
This libgo patch adjusts the hash and string fields computed by
reflect.StructOf to match the values that the compiler computes for a
struct type with the same field names and types.  This makes the
reflect code match the compiler's Type::hash_for_method and
Type::reflection methods.  This fixes https://golang.org/issue/25284.
Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu.  Committed
to mainline.

Ian
diff mbox series

Patch

Index: gcc/go/gofrontend/MERGE
===================================================================
--- gcc/go/gofrontend/MERGE	(revision 261216)
+++ gcc/go/gofrontend/MERGE	(working copy)
@@ -1,4 +1,4 @@ 
-8b6c7f3f9762366bab96ea95b966e93e2593be13
+baf289294a026ddd30c9e4341aff528084337763
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
Index: libgo/go/reflect/all_test.go
===================================================================
--- libgo/go/reflect/all_test.go	(revision 261216)
+++ libgo/go/reflect/all_test.go	(working copy)
@@ -4411,6 +4411,17 @@  func TestStructOf(t *testing.T) {
 	})
 	// check that type already in binary is found
 	checkSameType(t, StructOf(fields[2:3]), struct{ Y uint64 }{})
+
+	// gccgo used to fail this test.
+	type structFieldType interface{}
+	checkSameType(t,
+		StructOf([]StructField{
+			StructField{
+				Name: "F",
+				Type: TypeOf((*structFieldType)(nil)).Elem(),
+			},
+		}),
+		struct{ F structFieldType }{})
 }
 
 func TestStructOfExportRules(t *testing.T) {
Index: libgo/go/reflect/type.go
===================================================================
--- libgo/go/reflect/type.go	(revision 261216)
+++ libgo/go/reflect/type.go	(working copy)
@@ -1912,7 +1912,7 @@  func isValidFieldName(fieldName string)
 // This limitation may be lifted in a future version.
 func StructOf(fields []StructField) Type {
 	var (
-		hash       = uint32(0)
+		hash       = uint32(12)
 		size       uintptr
 		typalign   int8
 		comparable = true
@@ -1997,7 +1997,7 @@  func StructOf(fields []StructField) Type
 		}
 		fset[name] = struct{}{}
 
-		repr = append(repr, (" " + ft.String())...)
+		repr = append(repr, (" " + *ft.string)...)
 		if f.tag != nil {
 			repr = append(repr, (" " + strconv.Quote(*f.tag))...)
 		}