Source file
test/fixedbugs/issue33555.go
1
2
3
4
5
6
7
8
9
10 package main
11
12 import (
13 "bytes"
14 "fmt"
15 "io/ioutil"
16 "os"
17 "os/exec"
18 "path/filepath"
19 "strconv"
20 )
21
22 const start = `
23 package main
24
25 func main() {
26 println(f0() + 1)
27 }
28 `
29
30 const fn = `
31 //go:noinline
32 func f%d() int {
33 return f%d() + 1
34 }`
35
36 const fnlast = `
37 //go:noinline
38 func f%d() int {
39 return 0
40 }
41 `
42
43 const count = 400
44
45 func main() {
46 if err := test(); err != nil {
47 fmt.Fprintln(os.Stderr, err)
48 os.Exit(1)
49 }
50 }
51
52 func test() error {
53 var buf bytes.Buffer
54 buf.WriteString(start)
55 for i := 0; i < count; i++ {
56 fmt.Fprintf(&buf, fn, i, i + 1)
57 }
58 fmt.Fprintf(&buf, fnlast, count)
59
60 dir, err := ioutil.TempDir("", "issue33555")
61 if err != nil {
62 return err
63 }
64 defer os.RemoveAll(dir)
65
66 fn := filepath.Join(dir, "x.go")
67 if err := ioutil.WriteFile(fn, buf.Bytes(), 0644); err != nil {
68 return err
69 }
70
71 out, err := exec.Command("go", "run", fn).CombinedOutput()
72 if err != nil {
73 return err
74 }
75
76 want := strconv.Itoa(count + 1)
77 if got := string(bytes.TrimSpace(out)); got != want {
78 return fmt.Errorf("got %q want %q", got, want)
79 }
80
81 return nil
82 }
83
View as plain text