Text file src/cmd/compile/testdata/script/issue77033.txt

     1  go test -bench=Foo -cpuprofile=default.pgo
     2  go test -bench=Foo -pgo=default.pgo
     3  ! stdout 'FAIL'
     4  
     5  -- main_test.go --
     6  package main
     7  
     8  import (
     9  	"testing"
    10  )
    11  
    12  var a int
    13  
    14  func save(x int) {
    15  	a = x
    16  }
    17  
    18  func foo() {
    19  	for i := range yield1 {
    20  		defer save(i)
    21  	}
    22  }
    23  
    24  func yield1(yield func(int) bool) {
    25  	yield(1)
    26  }
    27  
    28  func BenchmarkFoo(b *testing.B) {
    29  	for i := 0; i < b.N; i++ {
    30  		foo()
    31  	}
    32  	if a != 1 {
    33  		b.Fatalf("a = %d; want 1", a)
    34  	}
    35  }
    36  
    37  -- go.mod --
    38  module demo
    39  
    40  go 1.24
    41  

View as plain text