]> Cypherpunks.ru repositories - gostls13.git/blob - test/fixedbugs/issue23837.go
cmd/compile/internal/inline: score call sites exposed by inlines
[gostls13.git] / test / fixedbugs / issue23837.go
1 // run
2
3 // Copyright 2018 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 package main
8
9 //go:noinline
10 func f(p, q *struct{}) bool {
11         return *p == *q
12 }
13
14 type T struct {
15         x struct{}
16         y int
17 }
18
19 //go:noinline
20 func g(p, q *T) bool {
21         return p.x == q.x
22 }
23
24 //go:noinline
25 func h(p, q func() struct{}) bool {
26         return p() == q()
27 }
28
29 func fi(p, q *struct{}) bool {
30         return *p == *q
31 }
32
33 func gi(p, q *T) bool {
34         return p.x == q.x
35 }
36
37 func hi(p, q func() struct{}) bool {
38         return p() == q()
39 }
40
41 func main() {
42         shouldPanic(func() { f(nil, nil) })
43         shouldPanic(func() { g(nil, nil) })
44         shouldPanic(func() { h(nil, nil) })
45         shouldPanic(func() { fi(nil, nil) })
46         shouldPanic(func() { gi(nil, nil) })
47         shouldPanic(func() { hi(nil, nil) })
48         n := 0
49         inc := func() struct{} {
50                 n++
51                 return struct{}{}
52         }
53         h(inc, inc)
54         if n != 2 {
55                 panic("inc not called")
56         }
57         hi(inc, inc)
58         if n != 4 {
59                 panic("inc not called")
60         }
61 }
62
63 func shouldPanic(x func()) {
64         defer func() {
65                 if recover() == nil {
66                         panic("did not panic")
67                 }
68         }()
69         x()
70 }