| 1 |
// run |
| 2 |
|
| 3 |
// Copyright 2016 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 |
// Make sure we don't start marshaling (writing to the stack) |
| 8 |
// arguments until those arguments are evaluated and known |
| 9 |
// not to unconditinally panic. If they unconditionally panic, |
| 10 |
// we write some args but never do the call. That messes up |
| 11 |
// the logic which decides how big the argout section needs to be. |
| 12 |
|
| 13 |
package main |
| 14 |
|
| 15 |
type W interface { |
| 16 |
Write([]byte) |
| 17 |
} |
| 18 |
|
| 19 |
type F func(W) |
| 20 |
|
| 21 |
func foo(f F) { |
| 22 |
defer func() { |
| 23 |
if r := recover(); r != nil { |
| 24 |
usestack(1000) |
| 25 |
} |
| 26 |
}() |
| 27 |
f(nil) |
| 28 |
} |
| 29 |
|
| 30 |
func main() { |
| 31 |
foo(func(w W) { |
| 32 |
var x []string |
| 33 |
w.Write([]byte(x[5])) |
| 34 |
}) |
| 35 |
} |
| 36 |
|
| 37 |
func usestack(n int) { |
| 38 |
if n == 0 { |
| 39 |
return |
| 40 |
} |
| 41 |
usestack(n - 1) |
| 42 |
} |