modernc.org/gc@v1.0.1-0.20240304020402-f0dba7c97c2b/testdata/errchk/test/fixedbugs/issue11053.dir/p_test.go (about) 1 // Copyright 2015 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package main 6 7 import ( 8 "fmt" 9 "p" 10 ) 11 12 type I interface { 13 Add(out *P) 14 } 15 16 type P struct { 17 V *int32 18 } 19 20 type T struct{} 21 22 var x int32 = 42 23 24 func Int32x(i int32) *int32 { 25 return &i 26 } 27 28 func (T) Add(out *P) { 29 out.V = p.Int32(x) // inlined, p.i.2 moved to heap 30 } 31 32 var PP P 33 var out *P = &PP 34 35 func F(s I) interface{} { 36 s.Add(out) // not inlined. 37 return out 38 } 39 40 var s T 41 42 func main() { 43 println("Starting") 44 fmt.Sprint(new(int32)) 45 resp := F(s).(*P) 46 println("Before, *resp.V=", *resp.V) // Trashes *resp.V in process of printing. 47 println("After, *resp.V=", *resp.V) 48 if got, want := *resp.V, int32(42); got != want { 49 fmt.Printf("FAIL, got %v, want %v", got, want) 50 } 51 }