]> Cypherpunks repositories - gostls13.git/commitdiff
misc/cgo/testshared: test that types and itabs are unique
authorKeith Randall <khr@golang.org>
Wed, 11 Jan 2017 23:02:16 +0000 (15:02 -0800)
committerKeith Randall <khr@golang.org>
Thu, 12 Jan 2017 00:20:55 +0000 (00:20 +0000)
Make sure that the same type and itab generated in two
different shared library are actually the same thing.

Change-Id: Ica45862d65ff8bc7ad04d59a41f57223f71224cd
Reviewed-on: https://go-review.googlesource.com/35115
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
misc/cgo/testshared/shared_test.go
misc/cgo/testshared/src/iface/main.go [new file with mode: 0644]
misc/cgo/testshared/src/iface_a/a.go [new file with mode: 0644]
misc/cgo/testshared/src/iface_b/b.go [new file with mode: 0644]
misc/cgo/testshared/src/iface_i/i.go [new file with mode: 0644]

index af4f91550f2094beb4152d5fb59b7d7252585054..f0766e511ec5b3e60f9365afa5d2154793d8349c 100644 (file)
@@ -815,3 +815,14 @@ func TestImplicitInclusion(t *testing.T) {
        goCmd(t, "install", "-linkshared", "implicitcmd")
        run(t, "running executable linked against library that contains same package as it", "./bin/implicitcmd")
 }
+
+// Tests to make sure that the type fields of empty interfaces and itab
+// fields of nonempty interfaces are unique even across modules,
+// so that interface equality works correctly.
+func TestInterface(t *testing.T) {
+       goCmd(t, "install", "-buildmode=shared", "-linkshared", "iface_a")
+       // Note: iface_i gets installed implicitly as a dependency of iface_a.
+       goCmd(t, "install", "-buildmode=shared", "-linkshared", "iface_b")
+       goCmd(t, "install", "-linkshared", "iface")
+       run(t, "running type/itab uniqueness tester", "./bin/iface")
+}
diff --git a/misc/cgo/testshared/src/iface/main.go b/misc/cgo/testshared/src/iface/main.go
new file mode 100644 (file)
index 0000000..3d5b54e
--- /dev/null
@@ -0,0 +1,17 @@
+// Copyright 2017 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+import "iface_a"
+import "iface_b"
+
+func main() {
+       if iface_a.F() != iface_b.F() {
+               panic("empty interfaces not equal")
+       }
+       if iface_a.G() != iface_b.G() {
+               panic("non-empty interfaces not equal")
+       }
+}
diff --git a/misc/cgo/testshared/src/iface_a/a.go b/misc/cgo/testshared/src/iface_a/a.go
new file mode 100644 (file)
index 0000000..e11047c
--- /dev/null
@@ -0,0 +1,17 @@
+// Copyright 2017 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package iface_a
+
+import "iface_i"
+
+//go:noinline
+func F() interface{} {
+       return (*iface_i.T)(nil)
+}
+
+//go:noinline
+func G() iface_i.I {
+       return (*iface_i.T)(nil)
+}
diff --git a/misc/cgo/testshared/src/iface_b/b.go b/misc/cgo/testshared/src/iface_b/b.go
new file mode 100644 (file)
index 0000000..47aee2e
--- /dev/null
@@ -0,0 +1,17 @@
+// Copyright 2017 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package iface_b
+
+import "iface_i"
+
+//go:noinline
+func F() interface{} {
+       return (*iface_i.T)(nil)
+}
+
+//go:noinline
+func G() iface_i.I {
+       return (*iface_i.T)(nil)
+}
diff --git a/misc/cgo/testshared/src/iface_i/i.go b/misc/cgo/testshared/src/iface_i/i.go
new file mode 100644 (file)
index 0000000..31c8038
--- /dev/null
@@ -0,0 +1,17 @@
+// Copyright 2017 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package iface_i
+
+type I interface {
+       M()
+}
+
+type T struct {
+}
+
+func (t *T) M() {
+}
+
+// *T implements I