From 046c65891952f1ee94c6580215eda7a4f21354e1 Mon Sep 17 00:00:00 2001 From: David Crawshaw Date: Fri, 29 Sep 2017 15:40:40 +0000 Subject: [PATCH] misc/cgo/testplugin: add test for issue 18584 Fixes #18584 Change-Id: I5f9428758999cacee49f3449e596e0a88bc06f91 Reviewed-on: https://go-review.googlesource.com/67150 Run-TryBot: David Crawshaw TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- misc/cgo/testplugin/src/issue18584/main.go | 23 ++++++++++++++++++++ misc/cgo/testplugin/src/issue18584/plugin.go | 19 ++++++++++++++++ misc/cgo/testplugin/test.bash | 9 ++++++-- 3 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 misc/cgo/testplugin/src/issue18584/main.go create mode 100644 misc/cgo/testplugin/src/issue18584/plugin.go diff --git a/misc/cgo/testplugin/src/issue18584/main.go b/misc/cgo/testplugin/src/issue18584/main.go new file mode 100644 index 0000000000..c280fd4620 --- /dev/null +++ b/misc/cgo/testplugin/src/issue18584/main.go @@ -0,0 +1,23 @@ +// 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 "plugin" + +func main() { + p, err := plugin.Open("plugin.so") + if err != nil { + panic(err) + } + + sym, err := p.Lookup("G") + if err != nil { + panic(err) + } + g := sym.(func() bool) + if !g() { + panic("expected types to match, Issue #18584") + } +} diff --git a/misc/cgo/testplugin/src/issue18584/plugin.go b/misc/cgo/testplugin/src/issue18584/plugin.go new file mode 100644 index 0000000000..be0868d375 --- /dev/null +++ b/misc/cgo/testplugin/src/issue18584/plugin.go @@ -0,0 +1,19 @@ +// 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 "reflect" + +type C struct { +} + +func F(c *C) *C { + return nil +} + +func G() bool { + var c *C + return reflect.TypeOf(F).Out(0) == reflect.TypeOf(c) +} diff --git a/misc/cgo/testplugin/test.bash b/misc/cgo/testplugin/test.bash index 3f964c1b04..a52aa46037 100755 --- a/misc/cgo/testplugin/test.bash +++ b/misc/cgo/testplugin/test.bash @@ -15,8 +15,8 @@ goos=$(go env GOOS) goarch=$(go env GOARCH) function cleanup() { - rm -f plugin*.so unnamed*.so iface*.so - rm -rf host pkg sub iface issue18676 issue19534 + rm -f plugin*.so unnamed*.so iface*.so issue* + rm -rf host pkg sub iface } trap cleanup EXIT @@ -61,3 +61,8 @@ _timeout 10s ./issue18676 GOPATH=$(pwd) go build -gcflags "$GO_GCFLAGS" -buildmode=plugin -ldflags='-pluginpath=issue.19534' -o plugin.so src/issue19534/plugin.go GOPATH=$(pwd) go build -gcflags "$GO_GCFLAGS" -o issue19534 src/issue19534/main.go ./issue19534 + +# Test for issue 18584 +GOPATH=$(pwd) go build -gcflags "$GO_GCFLAGS" -buildmode=plugin -o plugin.so src/issue18584/plugin.go +GOPATH=$(pwd) go build -gcflags "$GO_GCFLAGS" -o issue18584 src/issue18584/main.go +./issue18584 -- 2.48.1