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

View as plain text