Source file test/fixedbugs/issue4618.go

     1  // run
     2  
     3  // Copyright 2013 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  import (
    10  	"fmt"
    11  	"os"
    12  	"runtime"
    13  	"testing"
    14  )
    15  
    16  type T struct { int }
    17  
    18  var globl *T
    19  
    20  func F() {
    21  	t := &T{}
    22  	globl = t
    23  }
    24  
    25  func G() {
    26  	t := &T{}
    27  	_ = t
    28  }
    29  
    30  func main() {
    31  	nf := testing.AllocsPerRun(100, F)
    32  	ng := testing.AllocsPerRun(100, G)
    33  	if int(nf) > 1 {
    34  		fmt.Printf("AllocsPerRun(100, F) = %v, want 1\n", nf)
    35  		os.Exit(1)
    36  	}
    37  	if int(ng) != 0 && (runtime.Compiler != "gccgo" || int(ng) != 1) {
    38  		fmt.Printf("AllocsPerRun(100, G) = %v, want 0\n", ng)
    39  		os.Exit(1)
    40  	}
    41  }
    42  

View as plain text