OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [testsuite/] [go.test/] [test/] [stack.go] - Blame information for rev 700

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 700 jeremybenn
// $G $D/$F.go && $L $F.$A && ./$A.out
2
 
3
// Copyright 2009 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
// Try to tickle stack splitting bugs by doing
8
// go, defer, and closure calls at different stack depths.
9
 
10
package main
11
 
12
type T [20]int
13
 
14
func g(c chan int, t T) {
15
        s := 0
16
        for i := 0; i < len(t); i++ {
17
                s += t[i]
18
        }
19
        c <- s
20
}
21
 
22
func d(t T) {
23
        s := 0
24
        for i := 0; i < len(t); i++ {
25
                s += t[i]
26
        }
27
        if s != len(t) {
28
                println("bad defer", s)
29
                panic("fail")
30
        }
31
}
32
 
33
func f0() {
34
        // likely to make a new stack for f0,
35
        // because the call to f1 puts 3000 bytes
36
        // in our frame.
37
        f1()
38
}
39
 
40
func f1() [3000]byte {
41
        // likely to make a new stack for f1,
42
        // because 3000 bytes were used by f0
43
        // and we need 3000 more for the call
44
        // to f2.  if the call to morestack in f1
45
        // does not pass the frame size, the new
46
        // stack (default size 5k) will not be big
47
        // enough for the frame, and the morestack
48
        // check in f2 will die, if we get that far
49
        // without faulting.
50
        f2()
51
        return [3000]byte{}
52
}
53
 
54
func f2() [3000]byte {
55
        // just take up space
56
        return [3000]byte{}
57
}
58
 
59
var c = make(chan int)
60
var t T
61
var b = []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
62
 
63
func recur(n int) {
64
        ss := string(b)
65
        if len(ss) != len(b) {
66
                panic("bad []byte -> string")
67
        }
68
        go g(c, t)
69
        f0()
70
        s := <-c
71
        if s != len(t) {
72
                println("bad go", s)
73
                panic("fail")
74
        }
75
        f := func(t T) int {
76
                s := 0
77
                for i := 0; i < len(t); i++ {
78
                        s += t[i]
79
                }
80
                s += n
81
                return s
82
        }
83
        s = f(t)
84
        if s != len(t)+n {
85
                println("bad func", s, "at level", n)
86
                panic("fail")
87
        }
88
        if n > 0 {
89
                recur(n - 1)
90
        }
91
        defer d(t)
92
}
93
 
94
func main() {
95
        for i := 0; i < len(t); i++ {
96
                t[i] = 1
97
        }
98
        recur(8000)
99
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.