github.com/xushiwei/go@v0.0.0-20130601165731-2b9d83f45bc9/test/fixedbugs/bug368.go (about)

     1  // run
     2  
     3  // Copyright 2011 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  package main
     8  
     9  // 5g bug used to set up the 0 for -f() before calling f,
    10  // and the call to f smashed the register.
    11  
    12  func f(n int) int {
    13  	s := 0
    14  	for i := 0; i < n; i++ {
    15  		s += i>>1
    16  	}
    17  	return s
    18  }
    19  
    20  func main() {
    21  	x := -f(100)
    22  	if x != -2450 {
    23  		println(x)
    24  		panic("broken")
    25  	}
    26  }