summaryrefslogtreecommitdiffstats
path: root/test/fixedbugs/issue10958.go
blob: d0b39587bb8f8f011c38bcbde5aa639773c91a19 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// buildrun -t 10  -gcflags=-d=ssa/insert_resched_checks/on,ssa/check/on

//go:build !nacl && !js && disabled_see_issue_18589

// Copyright 2016 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// Test is disabled because it flakes when run in all.bash
// on some platforms, but is useful standalone to verify
// that rescheduling checks are working (and we may wish
// to investigate the flake, since it suggests that the
// loop rescheduling check may not work right on those
// platforms).

// This checks to see that call-free infinite loops do not
// block garbage collection.  IF YOU RUN IT STANDALONE without
// -gcflags=-d=ssa/insert_resched_checks/on in a not-experimental
// build, it should hang.

package main

import (
	"runtime"
)

var someglobal1 int
var someglobal2 int
var someglobal3 int

//go:noinline
func f() {}

func standinacorner1() {
	for someglobal1&1 == 0 {
		someglobal1++
		someglobal1++
	}
}

func standinacorner2(i int) {
	// contains an irreducible loop containing changes to memory
	if i != 0 {
		goto midloop
	}

loop:
	if someglobal2&1 != 0 {
		goto done
	}
	someglobal2++
midloop:
	someglobal2++
	goto loop

done:
	return
}

func standinacorner3() {
	for someglobal3&1 == 0 {
		if someglobal3&2 != 0 {
			for someglobal3&3 == 2 {
				someglobal3++
				someglobal3++
				someglobal3++
				someglobal3++
			}
		}
		someglobal3++
		someglobal3++
		someglobal3++
		someglobal3++
	}
}

func main() {
	go standinacorner1()
	go standinacorner2(0)
	go standinacorner3()
	// println("About to stand in a corner1")
	for someglobal1 == 0 {
		runtime.Gosched()
	}
	// println("About to stand in a corner2")
	for someglobal2 == 0 {
		runtime.Gosched()
	}
	// println("About to stand in a corner3")
	for someglobal3 == 0 {
		runtime.Gosched()
	}
	// println("About to GC")
	runtime.GC()
	// println("Success")
}