Source file test/fixedbugs/issue10958.go

     1  // buildrun -t 10  -gcflags=-d=ssa/insert_resched_checks/on,ssa/check/on
     2  
     3  //go:build !nacl && !js && disabled_see_issue_18589
     4  
     5  // Copyright 2016 The Go Authors. All rights reserved.
     6  // Use of this source code is governed by a BSD-style
     7  // license that can be found in the LICENSE file.
     8  
     9  // Test is disabled because it flakes when run in all.bash
    10  // on some platforms, but is useful standalone to verify
    11  // that rescheduling checks are working (and we may wish
    12  // to investigate the flake, since it suggests that the
    13  // loop rescheduling check may not work right on those
    14  // platforms).
    15  
    16  // This checks to see that call-free infinite loops do not
    17  // block garbage collection.  IF YOU RUN IT STANDALONE without
    18  // -gcflags=-d=ssa/insert_resched_checks/on in a not-experimental
    19  // build, it should hang.
    20  
    21  package main
    22  
    23  import (
    24  	"runtime"
    25  )
    26  
    27  var someglobal1 int
    28  var someglobal2 int
    29  var someglobal3 int
    30  
    31  //go:noinline
    32  func f() {}
    33  
    34  func standinacorner1() {
    35  	for someglobal1&1 == 0 {
    36  		someglobal1++
    37  		someglobal1++
    38  	}
    39  }
    40  
    41  func standinacorner2(i int) {
    42  	// contains an irreducible loop containing changes to memory
    43  	if i != 0 {
    44  		goto midloop
    45  	}
    46  
    47  loop:
    48  	if someglobal2&1 != 0 {
    49  		goto done
    50  	}
    51  	someglobal2++
    52  midloop:
    53  	someglobal2++
    54  	goto loop
    55  
    56  done:
    57  	return
    58  }
    59  
    60  func standinacorner3() {
    61  	for someglobal3&1 == 0 {
    62  		if someglobal3&2 != 0 {
    63  			for someglobal3&3 == 2 {
    64  				someglobal3++
    65  				someglobal3++
    66  				someglobal3++
    67  				someglobal3++
    68  			}
    69  		}
    70  		someglobal3++
    71  		someglobal3++
    72  		someglobal3++
    73  		someglobal3++
    74  	}
    75  }
    76  
    77  func main() {
    78  	go standinacorner1()
    79  	go standinacorner2(0)
    80  	go standinacorner3()
    81  	// println("About to stand in a corner1")
    82  	for someglobal1 == 0 {
    83  		runtime.Gosched()
    84  	}
    85  	// println("About to stand in a corner2")
    86  	for someglobal2 == 0 {
    87  		runtime.Gosched()
    88  	}
    89  	// println("About to stand in a corner3")
    90  	for someglobal3 == 0 {
    91  		runtime.Gosched()
    92  	}
    93  	// println("About to GC")
    94  	runtime.GC()
    95  	// println("Success")
    96  }
    97  

View as plain text