github.com/riscv/riscv-go@v0.0.0-20200123204226-124ebd6fcc8e/misc/cgo/testshared/src/exe/exe.go (about)

     1  package main
     2  
     3  import (
     4  	"depBase"
     5  	"os"
     6  	"reflect"
     7  	"runtime"
     8  )
     9  
    10  // Having a function declared in the main package triggered
    11  // golang.org/issue/18250
    12  func DeclaredInMain() {
    13  }
    14  
    15  type C struct {
    16  }
    17  
    18  func F() *C {
    19  	return nil
    20  }
    21  
    22  var slicePtr interface{} = &[]int{}
    23  
    24  func main() {
    25  	defer depBase.ImplementedInAsm()
    26  	// This code below causes various go.itab.* symbols to be generated in
    27  	// the executable. Similar code in ../depBase/dep.go results in
    28  	// exercising https://github.com/golang/go/issues/17594
    29  	reflect.TypeOf(os.Stdout).Elem()
    30  	runtime.GC()
    31  	depBase.V = depBase.F() + 1
    32  
    33  	var c *C
    34  	if reflect.TypeOf(F).Out(0) != reflect.TypeOf(c) {
    35  		panic("bad reflection results, see golang.org/issue/18252")
    36  	}
    37  
    38  	sp := reflect.New(reflect.TypeOf(slicePtr).Elem())
    39  	s := sp.Interface()
    40  
    41  	if reflect.TypeOf(s) != reflect.TypeOf(slicePtr) {
    42  		panic("bad reflection results, see golang.org/issue/18729")
    43  	}
    44  }