Source file src/cmd/compile/internal/test/issue57434_test.go

     1  // Copyright 2023 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package test
     6  
     7  import (
     8  	"testing"
     9  )
    10  
    11  var output int
    12  
    13  type Object struct {
    14  	Val int
    15  }
    16  
    17  func (o *Object) Initialize() *Object {
    18  	o.Val = 5
    19  	return o
    20  }
    21  
    22  func (o *Object) Update() *Object {
    23  	o.Val = o.Val + 1
    24  	return o
    25  }
    26  
    27  func TestAutotmpLoopDepth(t *testing.T) {
    28  	f := func() {
    29  		for i := 0; i < 10; i++ {
    30  			var obj Object
    31  			obj.Initialize().Update()
    32  			output = obj.Val
    33  		}
    34  	}
    35  	if n := testing.AllocsPerRun(10, f); n > 0 {
    36  		t.Error("obj moved to heap")
    37  	}
    38  }
    39  

View as plain text