Debian Codegraph @

gcc/testsuite/go.test/test/fixedbugs/issue33555.go

raw
1 // +build !nacl,!js,!gccgo
2 // run
3
4 // Copyright 2019 The Go Authors. All rights reserved.
5 // Use of this source code is governed by a BSD-style
6 // license that can be found in the LICENSE file.
7
8 // Test that the linker permits long call sequences.
9 package main
10
11 import (
12 "bytes"
13 "fmt"
14 "io/ioutil"
15 "os"
16 "os/exec"
17 "path/filepath"
18 "strconv"
19 )
20
21 const start = `
22 package main
23
24 func main() {
25 println(f0() + 1)
26 }
27 `
28
29 const fn = `
30 //go:noinline
31 func f%d() int {
32 return f%d() + 1
33 }`
34
35 const fnlast = `
36 //go:noinline
37 func f%d() int {
38 return 0
39 }
40 `
41
42 const count = 400
43
44 func main() {
45 if err := test(); err != nil {
46 fmt.Fprintln(os.Stderr, err)
47 os.Exit(1)
48 }
49 }
50
51 func test() error {
52 var buf bytes.Buffer
53 buf.WriteString(start)
54 for i := 0; i < count; i++ {
55 fmt.Fprintf(&buf, fn, i, i + 1)
56 }
57 fmt.Fprintf(&buf, fnlast, count)
58
59 dir, err := ioutil.TempDir("", "issue33555")
60 if err != nil {
61 return err
62 }
63 defer os.RemoveAll(dir)
64
65 fn := filepath.Join(dir, "x.go")
66 if err := ioutil.WriteFile(fn, buf.Bytes(), 0644); err != nil {
67 return err
68 }
69
70 out, err := exec.Command("go", "run", fn).CombinedOutput()
71 if err != nil {
72 return err
73 }
74
75 want := strconv.Itoa(count + 1)
76 if got := string(bytes.TrimSpace(out)); got != want {
77 return fmt.Errorf("got %q want %q", got, want)
78 }
79
80 return nil
81 }