1// runoutput
2
3// Copyright 2014 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// Check that {5,6,8,9}g/ggen.c:clearfat is zeroing the entire object.
8
9package main
10
11import (
12	"bytes"
13	"fmt"
14	"strconv"
15	"strings"
16)
17
18const ntest = 1100
19
20func main() {
21	var decls, calls bytes.Buffer
22
23	for i := 1; i <= ntest; i++ {
24		s := strconv.Itoa(i)
25		decls.WriteString(strings.Replace(decl, "$", s, -1))
26		calls.WriteString(strings.Replace("poison$()\n\tclearfat$()\n\t", "$", s, -1))
27	}
28
29	program = strings.Replace(program, "$DECLS", decls.String(), 1)
30	program = strings.Replace(program, "$CALLS", calls.String(), 1)
31	fmt.Print(program)
32}
33
34var program = `package main
35
36var count int
37
38$DECLS
39
40func main() {
41	$CALLS
42	if count != 0 {
43		println("failed", count, "case(s)")
44	}
45}
46`
47
48const decl = `
49func poison$() {
50	// Grow and poison the stack space that will be used by clearfat$
51	var t [2*$]byte
52	for i := range t {
53		t[i] = 0xff
54	}
55}
56
57func clearfat$() {
58	var t [$]byte
59
60	for _, x := range t {
61		if x != 0 {
62//			println("clearfat$: index", i, "expected 0, got", x)
63			count++
64			break
65		}
66	}
67}
68`
69