diff options
author | Martin Jambor <mjambor@suse.cz> | 2017-07-31 14:43:24 +0200 |
---|---|---|
committer | Martin Jambor <mjambor@suse.cz> | 2017-07-31 14:43:24 +0200 |
commit | b32f12dece884f1fa0f04c643a77105aff6ce8bc (patch) | |
tree | cdab5f10806561fc198f907299b0e55eb5701ef0 /libgo/misc/cgo/testshared/src | |
parent | 166bec868d991fdf71f9a66f994e5977fcab4aa2 (diff) | |
parent | a168a775e93ec31ae743ad282d8e60fa1c116891 (diff) | |
download | gcc-b32f12dece884f1fa0f04c643a77105aff6ce8bc.tar.gz |
Merge branch 'master' into gcngcn
Diffstat (limited to 'libgo/misc/cgo/testshared/src')
18 files changed, 253 insertions, 0 deletions
diff --git a/libgo/misc/cgo/testshared/src/dep2/dep2.go b/libgo/misc/cgo/testshared/src/dep2/dep2.go new file mode 100644 index 00000000000..c2c812adb9b --- /dev/null +++ b/libgo/misc/cgo/testshared/src/dep2/dep2.go @@ -0,0 +1,15 @@ +package dep2 + +import "depBase" + +var W int = 1 + +var hasProg depBase.HasProg + +type Dep2 struct { + depBase.Dep +} + +func G() int { + return depBase.F() + 1 +} diff --git a/libgo/misc/cgo/testshared/src/dep3/dep3.go b/libgo/misc/cgo/testshared/src/dep3/dep3.go new file mode 100644 index 00000000000..7b7c9dac1f9 --- /dev/null +++ b/libgo/misc/cgo/testshared/src/dep3/dep3.go @@ -0,0 +1,22 @@ +package dep3 + +// The point of this test file is that it references a type from +// depBase that is also referenced in dep2, but dep2 is loaded by the +// linker before depBase (because it is earlier in the import list). +// There was a bug in the linker where it would not correctly read out +// the type data in this case and later crash. + +import ( + "dep2" + "depBase" +) + +type Dep3 struct { + dep depBase.Dep + dep2 dep2.Dep2 +} + +func D3() int { + var x Dep3 + return x.dep.X + x.dep2.X +} diff --git a/libgo/misc/cgo/testshared/src/depBase/asm.s b/libgo/misc/cgo/testshared/src/depBase/asm.s new file mode 100644 index 00000000000..f203f8b0301 --- /dev/null +++ b/libgo/misc/cgo/testshared/src/depBase/asm.s @@ -0,0 +1,10 @@ +// Copyright 2014 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. + +//+build !gccgo + +#include "textflag.h" + +TEXT ·ImplementedInAsm(SB),NOSPLIT,$0-0 + RET diff --git a/libgo/misc/cgo/testshared/src/depBase/dep.go b/libgo/misc/cgo/testshared/src/depBase/dep.go new file mode 100644 index 00000000000..9f86710db01 --- /dev/null +++ b/libgo/misc/cgo/testshared/src/depBase/dep.go @@ -0,0 +1,33 @@ +package depBase + +import ( + "os" + "reflect" +) + +var SlicePtr interface{} = &[]int{} + +var V int = 1 + +var HasMask []string = []string{"hi"} + +type HasProg struct { + array [1024]*byte +} + +type Dep struct { + X int +} + +func (d *Dep) Method() int { + // This code below causes various go.itab.* symbols to be generated in + // the shared library. Similar code in ../exe/exe.go results in + // exercising https://github.com/golang/go/issues/17594 + reflect.TypeOf(os.Stdout).Elem() + return 10 +} + +func F() int { + defer func() {}() + return V +} diff --git a/libgo/misc/cgo/testshared/src/depBase/gccgo.go b/libgo/misc/cgo/testshared/src/depBase/gccgo.go new file mode 100644 index 00000000000..3e2b69b50bc --- /dev/null +++ b/libgo/misc/cgo/testshared/src/depBase/gccgo.go @@ -0,0 +1,5 @@ +//+build gccgo + +package depBase + +func ImplementedInAsm() {} diff --git a/libgo/misc/cgo/testshared/src/depBase/stubs.go b/libgo/misc/cgo/testshared/src/depBase/stubs.go new file mode 100644 index 00000000000..96573c12ece --- /dev/null +++ b/libgo/misc/cgo/testshared/src/depBase/stubs.go @@ -0,0 +1,5 @@ +//+build !gccgo + +package depBase + +func ImplementedInAsm() diff --git a/libgo/misc/cgo/testshared/src/exe/exe.go b/libgo/misc/cgo/testshared/src/exe/exe.go new file mode 100644 index 00000000000..84302a811f0 --- /dev/null +++ b/libgo/misc/cgo/testshared/src/exe/exe.go @@ -0,0 +1,44 @@ +package main + +import ( + "depBase" + "os" + "reflect" + "runtime" +) + +// Having a function declared in the main package triggered +// golang.org/issue/18250 +func DeclaredInMain() { +} + +type C struct { +} + +func F() *C { + return nil +} + +var slicePtr interface{} = &[]int{} + +func main() { + defer depBase.ImplementedInAsm() + // This code below causes various go.itab.* symbols to be generated in + // the executable. Similar code in ../depBase/dep.go results in + // exercising https://github.com/golang/go/issues/17594 + reflect.TypeOf(os.Stdout).Elem() + runtime.GC() + depBase.V = depBase.F() + 1 + + var c *C + if reflect.TypeOf(F).Out(0) != reflect.TypeOf(c) { + panic("bad reflection results, see golang.org/issue/18252") + } + + sp := reflect.New(reflect.TypeOf(slicePtr).Elem()) + s := sp.Interface() + + if reflect.TypeOf(s) != reflect.TypeOf(slicePtr) { + panic("bad reflection results, see golang.org/issue/18729") + } +} diff --git a/libgo/misc/cgo/testshared/src/exe2/exe2.go b/libgo/misc/cgo/testshared/src/exe2/exe2.go new file mode 100644 index 00000000000..675fd1f365c --- /dev/null +++ b/libgo/misc/cgo/testshared/src/exe2/exe2.go @@ -0,0 +1,8 @@ +package main + +import "dep2" + +func main() { + d := &dep2.Dep2{} + dep2.W = dep2.G() + 1 + d.Method() +} diff --git a/libgo/misc/cgo/testshared/src/exe3/exe3.go b/libgo/misc/cgo/testshared/src/exe3/exe3.go new file mode 100644 index 00000000000..643f2605f66 --- /dev/null +++ b/libgo/misc/cgo/testshared/src/exe3/exe3.go @@ -0,0 +1,7 @@ +package main + +import "dep3" + +func main() { + dep3.D3() +} diff --git a/libgo/misc/cgo/testshared/src/execgo/exe.go b/libgo/misc/cgo/testshared/src/execgo/exe.go new file mode 100644 index 00000000000..0427be8bdfd --- /dev/null +++ b/libgo/misc/cgo/testshared/src/execgo/exe.go @@ -0,0 +1,8 @@ +package main + +/* + */ +import "C" + +func main() { +} diff --git a/libgo/misc/cgo/testshared/src/explicit/explicit.go b/libgo/misc/cgo/testshared/src/explicit/explicit.go new file mode 100644 index 00000000000..6a4453f7758 --- /dev/null +++ b/libgo/misc/cgo/testshared/src/explicit/explicit.go @@ -0,0 +1,9 @@ +package explicit + +import ( + "implicit" +) + +func E() int { + return implicit.I() +} diff --git a/libgo/misc/cgo/testshared/src/iface/main.go b/libgo/misc/cgo/testshared/src/iface/main.go new file mode 100644 index 00000000000..3d5b54e73b9 --- /dev/null +++ b/libgo/misc/cgo/testshared/src/iface/main.go @@ -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/libgo/misc/cgo/testshared/src/iface_a/a.go b/libgo/misc/cgo/testshared/src/iface_a/a.go new file mode 100644 index 00000000000..e11047c166c --- /dev/null +++ b/libgo/misc/cgo/testshared/src/iface_a/a.go @@ -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/libgo/misc/cgo/testshared/src/iface_b/b.go b/libgo/misc/cgo/testshared/src/iface_b/b.go new file mode 100644 index 00000000000..47aee2e77ee --- /dev/null +++ b/libgo/misc/cgo/testshared/src/iface_b/b.go @@ -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/libgo/misc/cgo/testshared/src/iface_i/i.go b/libgo/misc/cgo/testshared/src/iface_i/i.go new file mode 100644 index 00000000000..31c80387c7e --- /dev/null +++ b/libgo/misc/cgo/testshared/src/iface_i/i.go @@ -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 diff --git a/libgo/misc/cgo/testshared/src/implicit/implicit.go b/libgo/misc/cgo/testshared/src/implicit/implicit.go new file mode 100644 index 00000000000..5360188c562 --- /dev/null +++ b/libgo/misc/cgo/testshared/src/implicit/implicit.go @@ -0,0 +1,5 @@ +package implicit + +func I() int { + return 42 +} diff --git a/libgo/misc/cgo/testshared/src/implicitcmd/implicitcmd.go b/libgo/misc/cgo/testshared/src/implicitcmd/implicitcmd.go new file mode 100644 index 00000000000..f6112933e56 --- /dev/null +++ b/libgo/misc/cgo/testshared/src/implicitcmd/implicitcmd.go @@ -0,0 +1,10 @@ +package main + +import ( + "explicit" + "implicit" +) + +func main() { + println(implicit.I() + explicit.E()) +} diff --git a/libgo/misc/cgo/testshared/src/trivial/trivial.go b/libgo/misc/cgo/testshared/src/trivial/trivial.go new file mode 100644 index 00000000000..da29a2cadf1 --- /dev/null +++ b/libgo/misc/cgo/testshared/src/trivial/trivial.go @@ -0,0 +1,4 @@ +package main + +func main() { +} |