Source file src/cmd/compile/internal/loopvar/testdata/opt-121.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  //go:build go1.21
     6  
     7  package main
     8  
     9  import (
    10  	"fmt"
    11  	"os"
    12  )
    13  
    14  var is []func() int
    15  
    16  func inline(j, k int) []*int {
    17  	var a []*int
    18  	for private := j; private < k; private++ {
    19  		a = append(a, &private)
    20  	}
    21  	return a
    22  }
    23  
    24  //go:noinline
    25  func notinline(j, k int) ([]*int, *int) {
    26  	for shared := j; shared < k; shared++ {
    27  		if shared == k/2 {
    28  			// want the call inlined, want "private" in that inline to be transformed,
    29  			// (believe it ends up on init node of the return).
    30  			// but do not want "shared" transformed,
    31  			return inline(j, k), &shared
    32  		}
    33  	}
    34  	return nil, &j
    35  }
    36  
    37  func main() {
    38  	a, p := notinline(2, 9)
    39  	fmt.Printf("a[0]=%d,*p=%d\n", *a[0], *p)
    40  	if *a[0] != 2 {
    41  		os.Exit(1)
    42  	}
    43  }
    44  

View as plain text