1// run 2 3// Copyright 2021 The Go Authors. All rights reserved. 4// Use of this source code is governed by a BSD-style 5// license that can be found in the LICENSE file. 6 7//go:build cgo 8 9package main 10 11import "runtime/cgo" 12 13type iface interface { 14 Get() int 15} 16 17type notInHeap struct { 18 _ cgo.Incomplete 19 i int 20} 21 22type myInt struct { 23 f *notInHeap 24} 25 26func (mi myInt) Get() int { 27 return int(mi.f.i) 28} 29 30type embed struct { 31 *myInt 32} 33 34var val = 1234 35 36var valNotInHeap = notInHeap{i: val} 37 38func main() { 39 i := val 40 check(i) 41 mi := myInt{f: &valNotInHeap} 42 check(mi.Get()) 43 ifv := iface(mi) 44 check(ifv.Get()) 45 ifv = iface(&mi) 46 check(ifv.Get()) 47 em := embed{&mi} 48 check(em.Get()) 49 ifv = em 50 check(ifv.Get()) 51 ifv = &em 52 check(ifv.Get()) 53} 54 55func check(v int) { 56 if v != val { 57 panic(v) 58 } 59} 60